aboutsummaryrefslogtreecommitdiff
path: root/lib/customisation.nix
diff options
context:
space:
mode:
authorSilvan Mosberger <infinisil@icloud.com>2019-09-05 00:16:01 +0200
committerSilvan Mosberger <infinisil@icloud.com>2019-09-05 00:57:55 +0200
commita4896cb4aab132c0bcc32c5df4440f6d3b7ec5de (patch)
treec88d6cf6acc255576a234466b6e6c493ed3d863e /lib/customisation.nix
parent23e72eff4197394e9dce69b20f55cff165e4409f (diff)
lib/makeOverridable: Refactor
- Rename ff to result because that's what it is - Better indentation - Less parens - Comment what overrideWith does
Diffstat (limited to 'lib/customisation.nix')
-rw-r--r--lib/customisation.nix25
1 files changed, 14 insertions, 11 deletions
diff --git a/lib/customisation.nix b/lib/customisation.nix
index cbc0604c2b40..b898e832cf5a 100644
--- a/lib/customisation.nix
+++ b/lib/customisation.nix
@@ -66,9 +66,11 @@ rec {
*/
makeOverridable = f: origArgs:
let
- ff = f origArgs;
+ 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
@@ -76,18 +78,19 @@ rec {
# Change the result of the function call by applying g to it
overrideResult = g: makeOverridable (copyArgs (args: g (f args))) origArgs;
in
- if builtins.isAttrs ff then (ff // {
- override = overrideArgs;
- overrideDerivation = fdrv: overrideResult (x: overrideDerivation x fdrv);
- ${if ff ? overrideAttrs then "overrideAttrs" else null} = fdrv:
- overrideResult (x: x.overrideAttrs fdrv);
- })
- else if lib.isFunction ff then
- # Transform ff into a functor while propagating its arguments
- lib.setFunctionArgs ff (lib.functionArgs ff) // {
+ if builtins.isAttrs result then
+ result // {
+ override = overrideArgs;
+ overrideDerivation = fdrv: overrideResult (x: overrideDerivation x fdrv);
+ ${if result ? overrideAttrs then "overrideAttrs" else null} = fdrv:
+ overrideResult (x: x.overrideAttrs fdrv);
+ }
+ else if lib.isFunction result then
+ # Transform the result into a functor while propagating its arguments
+ lib.setFunctionArgs result (lib.functionArgs result) // {
override = overrideArgs;
}
- else ff;
+ else result;
/* Call the package function in the file `fn' with the required