Add pkgsFor module arg

This enables modules to access packages given some system, outside of
per-system attributes.
This commit is contained in:
Archit Gupta 2024-01-09 23:52:36 -08:00
parent a7e2fe5468
commit bcaa85757e
3 changed files with 14 additions and 7 deletions

View File

@ -57,6 +57,7 @@ The following module arguments are available:
- `flakelight`: flakelight lib attribute
- `inputs`: value of inputs option
- `outputs`: resulting output (i.e. final flake attributes)
- `pkgsFor`: attrset mapping systems to the pkgs set for that system
- `moduleArgs`: All of the above arguments (passed to auto-loaded files)
## Additional pkgs values

View File

@ -5,7 +5,7 @@
{ config, inputs, lib, flakelight, ... }:
let
inherit (builtins) all head isAttrs length;
inherit (lib) foldAttrs getFiles getValues mapAttrs mergeAttrs mkOption
inherit (lib) foldAttrs genAttrs getFiles getValues mapAttrs mergeAttrs mkOption
mkOptionType showFiles showOption;
inherit (lib.types) functionTo lazyAttrsOf listOf nonEmptyStr raw uniq;
inherit (flakelight.types) optListOf overlay;
@ -20,6 +20,12 @@ let
(lazyAttrsOf outputs).merge loc defs
else throw "The option `${showOption loc}' has conflicting definitions in ${showFiles (getFiles defs)}";
};
pkgsFor = genAttrs config.systems (system: import inputs.nixpkgs {
inherit system;
inherit (config.nixpkgs) config;
overlays = config.withOverlays ++ [ config.packageOverlay ];
});
in
{
options = {
@ -54,16 +60,15 @@ in
};
config = {
_module.args = { inherit (config) inputs outputs; };
_module.args = {
inherit (config) inputs outputs;
inherit pkgsFor;
};
outputs = foldAttrs mergeAttrs { } (map
(system: mapAttrs
(_: v: { ${system} = v; })
(config.perSystem (import inputs.nixpkgs {
inherit system;
inherit (config.nixpkgs) config;
overlays = config.withOverlays ++ [ config.packageOverlay ];
})))
(config.perSystem pkgsFor.${system}))
config.systems);
};
}

View File

@ -9,6 +9,7 @@
, flakelight
, inputs
, outputs
, pkgsFor
, specialArgs
, modulesPath
, moduleArgs