diff options
author | Yueh-Shun Li <shamrocklee@posteo.net> | 2023-05-29 05:52:21 +0800 |
---|---|---|
committer | Yueh-Shun Li <shamrocklee@posteo.net> | 2023-11-07 01:58:48 +0000 |
commit | 6a8b6b8f720b8d6f43ea870164eb489de5316077 (patch) | |
tree | eb08e3c12603ed6b874ff41f052d00475324c8b9 | |
parent | a16319908e7bda2a9744114396e5e32a4ff6a3fc (diff) | |
download | nixpkgs-6a8b6b8f720b8d6f43ea870164eb489de5316077.tar nixpkgs-6a8b6b8f720b8d6f43ea870164eb489de5316077.tar.gz nixpkgs-6a8b6b8f720b8d6f43ea870164eb489de5316077.tar.bz2 nixpkgs-6a8b6b8f720b8d6f43ea870164eb489de5316077.tar.lz nixpkgs-6a8b6b8f720b8d6f43ea870164eb489de5316077.tar.xz nixpkgs-6a8b6b8f720b8d6f43ea870164eb489de5316077.tar.zst nixpkgs-6a8b6b8f720b8d6f43ea870164eb489de5316077.zip |
lib.makeOverridable: simplify function arguments preservation
Rename temporary variable copyArgs -> mirrorArgs. Use lib.mirrorFunctionArgs to define `mirrorArgs`. Apply mirrorArgs also to the returned function.
-rw-r--r-- | lib/customisation.nix | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/customisation.nix b/lib/customisation.nix index c7d40339d05..08fc5db0614 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -76,19 +76,22 @@ rec { Type: makeOverridable :: (AttrSet -> a) -> AttrSet -> a */ - makeOverridable = f: lib.setFunctionArgs - (origArgs: let + makeOverridable = f: + let + # Creates a functor with the same arguments as f + mirrorArgs = lib.mirrorFunctionArgs f; + in + mirrorArgs (origArgs: + let result = f origArgs; - # Creates a functor with the same arguments as f - copyArgs = g: lib.setFunctionArgs g (lib.functionArgs f); # Changes the original arguments with (potentially a function that returns) a set of new attributes overrideWith = newArgs: origArgs // (if lib.isFunction newArgs then newArgs origArgs else newArgs); # Re-call the function but with different arguments - overrideArgs = copyArgs (newArgs: makeOverridable f (overrideWith newArgs)); + overrideArgs = mirrorArgs (newArgs: makeOverridable f (overrideWith newArgs)); # Change the result of the function call by applying g to it - overrideResult = g: makeOverridable (copyArgs (args: g (f args))) origArgs; + overrideResult = g: makeOverridable (mirrorArgs (args: g (f args))) origArgs; in if builtins.isAttrs result then result // { @@ -102,8 +105,7 @@ rec { lib.setFunctionArgs result (lib.functionArgs result) // { override = overrideArgs; } - else result) - (lib.functionArgs f); + else result); /* Call the package function in the file `fn` with the required |