Struggling to use forAllSystems function in flake.nix

I have a flake containing my NixOS and HomeManager configurations, but I also wanted to add some shells I commonly use, such as a rust shell. I wanted to use a forAllSystems function to create an attribute set for each shell and avoid adding another flake input to do this for me. I’ve been struggling to get it working and most recently have been getting the error “error: flake output attribute ‘devShells.x86_64-linux.rust’ is not a derivation”

The relevant code snippets look like this

  let
      supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
      forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
      pkgsForSystem = system: 
        import nixpkgs {
          inherit system;
          config.allowUnfree = true;
          overlays = inputOverlays ++ [ localOverlays ];
        };
  in
    {
      devShells = forAllSystems (system:
          import ./shells { pkgs = pkgsForSystem system;}
        );
    }
shells/default.nix

{ pkgs, ... }:
{
  rust = ./rust.nix;
}

It works fine if I simply use devShells."x86_64-linux".rust = import ./shells/rust.nix { pkgs = pkgsForSystem "x86_64-linux"; };, so I know the issue is with my function, but I’m not sure what it is.

You may want to look at flake-utils, which has its own commonly used eachSystem functions rather than trying to roll your own.

I also put out nosys recently to make systems handling less tedious in general as another option. The benefit here is that your output functor looks just like a regular one without having to worry about passing around system all over the place.

1 Like

I thought about using flake-utils, but I struggled to get that working and also wanted to understand myself how the functions were working.

I ended up getting it working with

      devShells = genSystems (system: {
        rust = import ./shells/rust.nix { pkgs = pkgsFor system}; };
      });

so the issue must’ve been with importing the shells/default.nix file and it also likely wouldn’t have worked with flake-utils. Thanks for showing me nosys though, it looks very interesting.

1 Like