summaryrefslogtreecommitdiff
path: root/lib/types.nix
diff options
context:
space:
mode:
authorWroclaw <wroclaw223@outlook.com>2025-03-01 18:16:38 +0100
committerWroclaw <wroclaw223@outlook.com>2025-03-02 00:04:19 +0100
commit0de1d18795089b381d72a35fc4c3b178e26f7c06 (patch)
tree7245d4266349b36f47facf1a635a460788353105 /lib/types.nix
parentemacsPackages.elpaca: 0-unstable-2025-02-07 -> 0-unstable-2025-02-16 (diff)
downloadnixpkgs-0de1d18795089b381d72a35fc4c3b178e26f7c06.tar.gz
lib.types.functionTo: preserve functionArgs
Previously if function in defs had set pattern in argument, this information would be lost. This keeps functionArgs in set pattern, by using functor and `__functionArgs` that is later used by `lib.functionArgs`.
Diffstat (limited to 'lib/types.nix')
-rw-r--r--lib/types.nix9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/types.nix b/lib/types.nix
index cda048fd10ca..cdba500ae07f 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -873,8 +873,13 @@ rec {
description = "function that evaluates to a(n) ${optionDescriptionPhrase (class: class == "noun" || class == "composite") elemType}";
descriptionClass = "composite";
check = isFunction;
- merge = loc: defs:
- fnArgs: (mergeDefinitions (loc ++ [ "<function body>" ]) elemType (map (fn: { inherit (fn) file; value = fn.value fnArgs; }) defs)).mergedValue;
+ merge = loc: defs: {
+ # An argument attribute has a default when it has a default in all definitions
+ __functionArgs = lib.zipAttrsWith (_: lib.all (x: x)) (
+ lib.map (fn: lib.functionArgs fn.value) defs
+ );
+ __functor = _: callerArgs: (mergeDefinitions (loc ++ [ "<function body>" ]) elemType (map (fn: { inherit (fn) file; value = fn.value callerArgs; }) defs)).mergedValue;
+ };
getSubOptions = prefix: elemType.getSubOptions (prefix ++ [ "<function body>" ]);
getSubModules = elemType.getSubModules;
substSubModules = m: functionTo (elemType.substSubModules m);