From a4896cb4aab132c0bcc32c5df4440f6d3b7ec5de Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 5 Sep 2019 00:16:01 +0200 Subject: lib/makeOverridable: Refactor - Rename ff to result because that's what it is - Better indentation - Less parens - Comment what overrideWith does --- lib/customisation.nix | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'lib/customisation.nix') diff --git a/lib/customisation.nix b/lib/customisation.nix index cbc0604c2b4..b898e832cf5 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 -- cgit 1.4.1