flake-utils icon indicating copy to clipboard operation
flake-utils copied to clipboard

self parameter for eachSystem/eachDefaultSystem

Open WizardUli opened this issue 3 years ago • 2 comments

When you want to reference a package from another package, or a devShell, etc... inside eachSystem/eachDefaultSystem closure then you have to either use the pesky rec keyword which even does not work for all cases or you have to use self parameter from the flake itself like self.${system}.packages.abc which is unnecessarily repeating the system.

I propose adding a variant of eachSystem/eachDefaultSystem which could be used like this:

{
  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem2 (sself: system: {
      packages.abc = ...;

      devShells.default = pkgs.mkShell {
        packages = [
          sself.packages.abc # Instead of self.${system}.packages.abc;
        ];
      };
    });
}

Perhaps it could be made backward compatible similar to overrideAttrs (https://github.com/NixOS/nixpkgs/pull/119942) so new variant of eachSystem may not be necessary.

WizardUli avatar Aug 09 '22 21:08 WizardUli

That's a good observation. As long as it doesn't break backwards compatibility, I don't mind extending the existing functions. Otherwise, it's probably best to introduce a new one (if you're sending a PR).

zimbatm avatar Aug 10 '22 12:08 zimbatm

fwiw, divnix/nosys does just what you are looking for. I did start #83 to maybe see if there was interest in bringing this functionality to live here.

nrdxp avatar Nov 15 '22 21:11 nrdxp