numtide / flake-utils

Pure Nix flake utility functions [maintainer=@zimbatm]
MIT License
1.19k stars 78 forks source link

Make system map more composible #42

Closed andyrichardson closed 2 years ago

andyrichardson commented 3 years ago

About

When making a flake, it would be much more useful if I could compose flake-utils like this

{
  # ...
  outputs = { self, nixpkgs, flake-utils, ... }: with flake-utils.lib; {
    nixosConfigurations.nixos = ;# ...
    packages = eachSystemMap allSystems (system: import nixpkgs { inherit system; });
    defaultPackage = eachSystemMap allSystems (system: self.packages.${system}.somePackage );
  };
}

Rather than having to do this

{
  # ...
  outputs = { self, nixpkgs, flake-utils, ... }: with flake-utils.lib;
    nixpkgs.lib.mkMerge [
      ({ nixosConfigurations.nixos = ; })
      (eachSystem allSystems (system: {
        packages = import nixpkgs { inherit system; };
        defaultPackage = self.packages.${system}.somePackage;
      }))
  ];
}

Mental model

Coming from other languages, I think this would be more obvious

# Input
{
  parent = eachSystemMap ["a" "b"] (system: "hello" );
}
# Output
{
  parent = {
    a = "hello";
    b = "hello";
  };
}

Than this

# Input
eachSystemMap ["a" "b"] (system: { parent = "hello";  })
# Output
{
  parent = {
    a = "hello";
    b = "hello";
  };
}
zimbatm commented 2 years ago

Makes sense. This is already possible with nixpkgs.lib.genAttrs actually but the name is better here.

ck3d commented 2 years ago

Is there a reason why the new eachSystemMap is not exposed via lib?

zimbatm commented 2 years ago

It means that @andyrichardson didn't test the change. Pushed a follow-up commit in 3cecb5b042f7f209c56ffd8371b2711a290ec797