diff --git a/API_GUIDE.md b/API_GUIDE.md index ccfc724..70814af 100644 --- a/API_GUIDE.md +++ b/API_GUIDE.md @@ -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 diff --git a/builtinModules/core.nix b/builtinModules/core.nix index e7c0b3f..6da6c89 100644 --- a/builtinModules/core.nix +++ b/builtinModules/core.nix @@ -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); }; } diff --git a/builtinModules/moduleArgs.nix b/builtinModules/moduleArgs.nix index 746592e..1982ca8 100644 --- a/builtinModules/moduleArgs.nix +++ b/builtinModules/moduleArgs.nix @@ -9,6 +9,7 @@ , flakelight , inputs , outputs +, pkgsFor , specialArgs , modulesPath , moduleArgs