about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2022-10-07 09:58:55 +0200
committerMaximilian Bosch <maximilian@mbosch.me>2022-10-07 10:01:44 +0200
commitac48f07282b1e71614f198a241e8f08b252ed509 (patch)
treee067ff3b0388c84d7330b27851ea67b9414b33f5 /lib
parent352ed567a786e4c0f9c7a0838783fd9a84e85c5a (diff)
lib/types: always use `<function body>` instead of `[function body]` to indicate a function inside an option structure
The motivation is to have a single identifier for that. Useful for the
next commit where I'll try to escape option-parts correctly (options can
be any kind of strings, but unless these are Nix identifiers, they must
be quoted).

Since `<function body>` (or `<name>`/`*`) are special identifiers in
error messages and the manual, we need a unique way to mark an option
part as function call because these are not to be quoted.
Diffstat (limited to 'lib')
-rwxr-xr-xlib/tests/modules.sh4
-rw-r--r--lib/types.nix4
2 files changed, 4 insertions, 4 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index 57d3b5a76cec1..2be9b5835090c 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -302,11 +302,11 @@ checkConfigOutput '^"baz"$' config.value.nested.bar.baz ./types-anything/mk-mods
 ## types.functionTo
 checkConfigOutput '^"input is input"$' config.result ./functionTo/trivial.nix
 checkConfigOutput '^"a b"$' config.result ./functionTo/merging-list.nix
-checkConfigError 'A definition for option .fun.\[function body\]. is not of type .string.. Definition values:\n\s*- In .*wrong-type.nix' config.result ./functionTo/wrong-type.nix
+checkConfigError 'A definition for option .fun.<function body>. is not of type .string.. Definition values:\n\s*- In .*wrong-type.nix' config.result ./functionTo/wrong-type.nix
 checkConfigOutput '^"b a"$' config.result ./functionTo/list-order.nix
 checkConfigOutput '^"a c"$' config.result ./functionTo/merging-attrs.nix
 checkConfigOutput '^"a bee"$' config.result ./functionTo/submodule-options.nix
-checkConfigOutput '^"fun.\[function body\].a fun.\[function body\].b"$' config.optionsResult ./functionTo/submodule-options.nix
+checkConfigOutput '^"fun.<function body>.a fun.<function body>.b"$' config.optionsResult ./functionTo/submodule-options.nix
 
 # moduleType
 checkConfigOutput '^"a b"$' config.resultFoo ./declare-variants.nix ./define-variant.nix
diff --git a/lib/types.nix b/lib/types.nix
index 9b2c5e846ad15..db5ae03d6fe92 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -616,8 +616,8 @@ rec {
       descriptionClass = "composite";
       check = isFunction;
       merge = loc: defs:
-        fnArgs: (mergeDefinitions (loc ++ [ "[function body]" ]) elemType (map (fn: { inherit (fn) file; value = fn.value fnArgs; }) defs)).mergedValue;
-      getSubOptions = prefix: elemType.getSubOptions (prefix ++ [ "[function body]" ]);
+        fnArgs: (mergeDefinitions (loc ++ [ "<function body>" ]) elemType (map (fn: { inherit (fn) file; value = fn.value fnArgs; }) defs)).mergedValue;
+      getSubOptions = prefix: elemType.getSubOptions (prefix ++ [ "<function body>" ]);
       getSubModules = elemType.getSubModules;
       substSubModules = m: functionTo (elemType.substSubModules m);
       functor = (defaultFunctor "functionTo") // { wrapped = elemType; };