diff --git a/lib/modules.nix b/lib/modules.nix index 5c2fb48868c1f..eaef9c55cb2fc 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -13,6 +13,7 @@ let elem filter foldl' + functionArgs getAttrFromPath head id @@ -510,7 +511,7 @@ let # context on the explicit arguments of "args" too. This update # operator is used to make the "args@{ ... }: with args.lib;" notation # works. - in f (args // extraArgs); + in f (builtins.intersectAttrs (functionArgs f) (args // extraArgs)); /* Merge a list of modules. This will recurse over the option declarations in all modules, combining them into a single set. diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 2c5e4cdbcec10..f6f8223d95349 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -433,6 +433,9 @@ checkConfigError 'Could not load a value as a module, because it is of type "fla checkConfigOutput '^true$' "$@" config.enable ./declare-enable.nix ./define-enable-with-top-level-mkIf.nix checkConfigError 'Could not load a value as a module, because it is of type "configuration", in file .*/import-configuration.nix.*please only import the modules that make up the configuration.*' config ./import-configuration.nix +checkConfigOutput '"foo"' config.foo ./no-ellipsis-module.nix +checkConfigOutput '"foo"' config.foo ./module-with-at-pattern.nix + # doRename works when `warnings` does not exist. checkConfigOutput '^1234$' config.c.d.e ./doRename-basic.nix # doRename adds a warning. diff --git a/lib/tests/modules/module-with-at-pattern.nix b/lib/tests/modules/module-with-at-pattern.nix new file mode 100644 index 0000000000000..48e49e159ffb0 --- /dev/null +++ b/lib/tests/modules/module-with-at-pattern.nix @@ -0,0 +1,5 @@ +# this no longer works since functionArgs is blind to both `...` and `@`-patterns +{ ... }@inputs: { + options.foo = inputs.lib.mkOption { type = inputs.lib.types.str; }; + config.foo = "foo"; +} diff --git a/lib/tests/modules/no-ellipsis-module.nix b/lib/tests/modules/no-ellipsis-module.nix new file mode 100644 index 0000000000000..9c2d59f92f043 --- /dev/null +++ b/lib/tests/modules/no-ellipsis-module.nix @@ -0,0 +1,5 @@ +# the module can now request only what it needs without a `...`. +{ lib }: { + options.foo = lib.mkOption { type = lib.types.str; }; + config.foo = "foo"; +}