Regenerate the world

  • no
  • Posts

Posts

October 2, 2023

The Climate Crisis Post 0

This is the zeroth edition of the weekly climate crisis post where I collect important research, news, myth busting, recommendations, calls and hopefully some good news too.

Climate news

The Rosebank field leads to demonstrations against Equinor all over the world (I was there) and lawsuits https://www.transitmag.no/2023/09/27/britiske-myndigheter-godkjenner-equinors-rosebank-felt-klimaaktivister-varsler-soksmal/

Stop Rosebank

Norway is being sued for lack of climate action in several cases before the European Court of Human Rights. https://www.transitmag.no/2023/09/27/norge-pa-anklagbenken-historisk-stor-klimasak-opp-for-den-europeiske-mensnerettsdomstolen/ This is in addition to a separate lawsuit against Norwegian oil developments and the new climate lawsuit: https://www.greenpeace.org/norway/klimaendringer/klimasoksmal/nytt-klimasoksmal-2023-dette-ma-du-vite/

read more
November 4, 2021

Building C libraries in Nix

Nix is a great tool for deterministic, and soon properly content addressed, builds. However my experience is that it is really hard to go beyond the trivial usages of nix. I had to compile some C code using nix and I wrote this expression:

# A very simple setup to compile C and C++ code
{ pkgs, system, lib }:
with builtins;
let
  inherit (pkgs) legacyPackages;
  inherit (legacyPackages.${system}) stdenv;
  joinArgs = lib.concatStringsSep " ";
  pathOfLib = dep: dep.libPath or "${dep}/${dep.libName or dep.name}";
  protoBuildCLib = lib.makeOverridable
    ({ name
     , src
     , static ? false
     , libExtension ? if static then "a" else "so"
     , libName ? "lib${name}.${libExtension}"
     , cc ? stdenv.cc
       # A function that can update the cc options.
     , updateCCOptions ? a: a
     , sourceFiles ? [ "*.c" ]
     , debug ? false
     , extraDrvArgs ? {}
     # Static libraries that wil be included in the resulting lib
     , staticLibDeps ? []
     # Shared libraries to link to
     , sharedLibDeps ? []
     }:
      let
        defaultOptions = [ "-Wall" "-pedantic" "-O3" (if debug then "-ggdb" else "") ];
        commonCCOptions = updateCCOptions defaultOptions;
        libs = map (drv: "${drv}/${drv.name}") staticLibDeps;
        linkerOpts = map (drv: "-L${drv}") sharedLibDeps;
        objectFiles = [ "*.o" ];
        buildSteps =
          if static then
            [
              "${cc}/bin/cc ${joinArgs commonCCOptions} -c ${joinArgs sourceFiles}"
              "ar rcs ${libName} ${joinArgs objectFiles}"

            ] else
            [
              "${cc}/bin/cc ${joinArgs commonCCOptions} -c ${joinArgs sourceFiles}"
              "${cc}/bin/cc ${joinArgs commonCCOptions} -shared -Wl,--whole-archive ${joinArgs libs} ${joinArgs objectFiles} -Wl,--no-whole-archive ${joinArgs linkerOpts} -o ${libName}"
            ];
      in
      stdenv.mkDerivation ({
        inherit src system;
        name = libName;
        buildInputs = with legacyPackages.${system}; [ cc clib ] ++ staticLibDeps;
        NIX_DEBUG = 1;
        buildPhase = pkgs.lib.concatStringsSep "\n" buildSteps;
        installPhase = ''
          mkdir -p $out
          cp ${libName} $out
        '';
      } // extraDrvArgs));

  # type: {a = b;} -> (a -> b -> c) -> [c]
  forEachRow = attrset: f: lib.zipListsWith f (attrNames attrset) (attrValues attrset);
  forEachRowJoin = attrset: f: lib.foldl (acc: c: acc // c) { } (forEachRow attrset f);
  # Extend an overridable function with the given overrideArgs.
  extendOverridableFn = (f: overrideArgs: args:
    let
      self = f args;
      newProps = forEachRowJoin overrideArgs (name: attrs: { ${name} = self.override attrs; });
    in
    self // newProps
  );
  # Property extensions. Each generation inherits the properties of the last.
  propertyGenerations = [
    {
      debug = { debug = true; };
    }
    {
      staticLib = {
        static = true;
      };
      sharedLib = {
        static = false;
      };
    }
  ];

  # Add additional properties in sequence
  buildCLib = lib.foldl extendOverridableFn protoBuildCLib propertyGenerations;
in
buildCLib

Things I noticed is that nix tooling has a long way to go before there will be a really smooth developer experience. The new flakes interface is very nice and I use it all the time. I’m really looking forwards to when typed nix projects like Nickel or DHall become mature.

read more
July 14, 2020

A quick look at the Formality language

After reading this article I got excited. Apparently it is possible to create a proof language that is both performant, total and reliable. This is one of the things that drew me to Haskell - the idea that the language and compiler should be able to enforce strict rules of correctness. It does not support dependent types though and therefore cannot prove most theorems. Dependent types allows for value level computations at compile time and makes it possible to constrain types arbitrarily. This is because there is no native types and types are at the same level as values and can be used as values.

read more
July 14, 2020

How I moved my homepage to IPFS

I just moved my homepage over to IPFS! The Inter Planetary File System has been around a while, but I didn’t hear about it until recently. Hosting your static home page on ipfs is not so difficult, but the guides can be a bit confusing. So here is a short summary of what I did.

ipfs

Adding the site

I installed the ipfs cli following the instructions. First I needed to launch the ipfs daemon with

read more
July 14, 2020

Making a game in Haskell

Making a game in Haskell

During my vacation I’ve been working on making a game in Haskell called HexTech. It has been really fun and inspiring and I’ve learned a lot of new things. The game is a sort of turn-based strategy game on a hexagonal grid. It is mostly a hobby project and it has taken more time than I wanted, but I have been making steady progress. I’m using several tutorials as a guide: this guide for working with hexagonal grids and this one which really gave me a kick start. A lot of my source is based on a rewrite of that game code.

read more
October 30, 2019

Fumbling with Functional Programming

Fumbling with Functional Programming

I love functional programming. It’s just much more beautiful than imperative programming. The down sides usually comes from wanting things done and access to public libraries. I will argue here why FP is worth the effort and reflect around some of the issues in the communities.

For many programmers functional programming can be seen as nothing more than a curiosity. After all, you can seemingly do the same things with imperative languages like Java or C++. Functional programming is a paradigm first and foremost; not restricted to particular languages. Instead of just making “code that works” you should try to emulate the pure mathematical structure lurking behind every problem. This is not something that comes for free. You have to really understand the problem, but then you can write particularly elegant solutions that you can trust.

read more
  • ««
  • «
  • 1
  • 2
  • 3
  • 4
  • 5
  • »
  • »»
© Regenerate the world 2025