hallettj,
@hallettj@beehaw.org avatar

I sometimes write a flake with those 4 lines of Nix code, and it comes out just messy enough that tbh I’m happier adding an input to handle that. But I recently learned that the nixpkgs flake exports the lib.* helpers through nixpkgs.lib (as opposed to nixpkgs.legacyPackages.${system}.lib) so you can call helpers before specifying a system. And nixpkgs.lib.genAttrs is kinda close enough to flake-utils.lib.eachSystem that it might make a better solution.

Like where with flake-utils you would write,


<span style="color:#323232;">flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-darwin" ] (system:
</span><span style="color:#323232;">let
</span><span style="color:#323232;">  pkgs = nixpkgs.legacyPackages.${system};
</span><span style="color:#323232;">in
</span><span style="color:#323232;">{
</span><span style="color:#323232;">  devShells.default = pkgs.mkShell {
</span><span style="color:#323232;">    nativeBuildInputs = with pkgs; [
</span><span style="color:#323232;">      hello
</span><span style="color:#323232;">    ];
</span><span style="color:#323232;">  };
</span><span style="color:#323232;">})
</span>

Instead you can use genAttrs,


<span style="color:#323232;">let
</span><span style="color:#323232;">  forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-darwin" ];
</span><span style="color:#323232;">  pkgs = forAllSystems (system:
</span><span style="color:#323232;">    nixpkgs.legacyPackages.${system}
</span><span style="color:#323232;">  );
</span><span style="color:#323232;">in
</span><span style="color:#323232;">{
</span><span style="color:#323232;">  devShells = forAllSystems (system: {
</span><span style="color:#323232;">    default = pkgs.${system}.mkShell {
</span><span style="color:#323232;">      nativeBuildInputs = with pkgs.${system}; [
</span><span style="color:#323232;">        hello
</span><span style="color:#323232;">      ];
</span><span style="color:#323232;">    };
</span><span style="color:#323232;">  });
</span><span style="color:#323232;">}
</span>

It’s more verbose, but it makes the structure of outputs more transparent.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • linux@lemmy.ml
  • localhost
  • All magazines
  • Loading…
    Loading the web debug toolbar…
    Attempt #