1
1
forked from extern/flakelight

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 - `flakelight`: flakelight lib attribute
- `inputs`: value of inputs option - `inputs`: value of inputs option
- `outputs`: resulting output (i.e. final flake attributes) - `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) - `moduleArgs`: All of the above arguments (passed to auto-loaded files)
## Additional pkgs values ## Additional pkgs values

View File

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

View File

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