summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorRobert Hensing <roberth@users.noreply.github.com>2023-08-02 20:12:37 +0200
committerGitHub <noreply@github.com>2023-08-02 20:12:37 +0200
commit53b289836b041a1e05d833e91065e4346f9a2de0 (patch)
treea28fb0efbebe9c602044940fe1783af85eaf093c /lib
parent634dcffbee87c8e78f95504ca808b1ab28f00c1a (diff)
parent72f2c8d6c681590d8c973bb79bdd21060aec9c53 (diff)
downloadnixpkgs-53b289836b041a1e05d833e91065e4346f9a2de0.tar
nixpkgs-53b289836b041a1e05d833e91065e4346f9a2de0.tar.gz
nixpkgs-53b289836b041a1e05d833e91065e4346f9a2de0.tar.bz2
nixpkgs-53b289836b041a1e05d833e91065e4346f9a2de0.tar.lz
nixpkgs-53b289836b041a1e05d833e91065e4346f9a2de0.tar.xz
nixpkgs-53b289836b041a1e05d833e91065e4346f9a2de0.tar.zst
nixpkgs-53b289836b041a1e05d833e91065e4346f9a2de0.zip
Merge pull request #243139 from hercules-ci/modules-test-default-argument
lib/tests/modules: Test that _module.args works when a default argumeā€¦
Diffstat (limited to 'lib')
-rwxr-xr-xlib/tests/modules.sh22
-rw-r--r--lib/tests/modules/module-argument-default.nix9
2 files changed, 31 insertions, 0 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index 4adbd69effb..b933a24a57a 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -69,6 +69,28 @@ checkConfigOutput '^"one two"$' config.result ./shorthand-meta.nix
 
 checkConfigOutput '^true$' config.result ./test-mergeAttrDefinitionsWithPrio.nix
 
+# Check that a module argument is passed, also when a default is available
+# (but not needed)
+#
+# When the default is needed, we currently fail to do what the users expect, as
+# we pass our own argument anyway, even if it *turns out* not to exist.
+#
+# The reason for this is that we don't know at invocation time what is in the
+# _module.args option. That value is only available *after* all modules have been
+# invoked.
+#
+# Hypothetically, Nix could help support this by giving access to the default
+# values, through a new built-in function.
+# However the default values are allowed to depend on other arguments, so those
+# would have to be passed in somehow, making this not just a getter but
+# something more complicated.
+#
+# At that point we have to wonder whether the extra complexity is worth the cost.
+# Another - subjective - reason not to support it is that default values
+# contradict the notion that an option has a single value, where _module.args
+# is the option.
+checkConfigOutput '^true$' config.result ./module-argument-default.nix
+
 # types.pathInStore
 checkConfigOutput '".*/store/0lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv"' config.pathInStore.ok1 ./types.nix
 checkConfigOutput '".*/store/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15"' config.pathInStore.ok2 ./types.nix
diff --git a/lib/tests/modules/module-argument-default.nix b/lib/tests/modules/module-argument-default.nix
new file mode 100644
index 00000000000..8dbb783e2df
--- /dev/null
+++ b/lib/tests/modules/module-argument-default.nix
@@ -0,0 +1,9 @@
+{ a ? false, lib, ... }: {
+  options = {
+    result = lib.mkOption {};
+  };
+  config = {
+    _module.args.a = true;
+    result = a;
+  };
+}