Add moduleWithSystem flake module parameter
This commit is contained in:
parent
608ed35022
commit
e646df196a
3 changed files with 51 additions and 0 deletions
32
modules/moduleWithSystem.nix
Normal file
32
modules/moduleWithSystem.nix
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{ config, lib, withSystem, ... }:
|
||||
{
|
||||
config = {
|
||||
_module.args = {
|
||||
moduleWithSystem =
|
||||
module:
|
||||
|
||||
{ config, ... }:
|
||||
let
|
||||
system =
|
||||
config._module.args.system or
|
||||
config._module.args.pkgs.stdenv.hostPlatform.system or
|
||||
(throw "moduleWithSystem: Could not determine the configuration's system parameter for this module system application.");
|
||||
|
||||
allArgs = withSystem system (args: args);
|
||||
|
||||
lazyArgsPerParameter = f: builtins.mapAttrs
|
||||
(k: v: allArgs.${k} or (throw "moduleWithSystem: module argument `${k}` does not exist."))
|
||||
(builtins.functionArgs f);
|
||||
|
||||
# Use reflection to make the call lazy in the argument.
|
||||
# Restricts args to the ones declared.
|
||||
callLazily = f: a: f (lazyArgsPerParameter f);
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
(callLazily module allArgs)
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue