lib/makeOverridable: Refactor
- Rename ff to result because that's what it is - Better indentation - Less parens - Comment what overrideWith does
This commit is contained in:
parent
23e72eff41
commit
a4896cb4aa
|
@ -66,9 +66,11 @@ rec {
|
||||||
*/
|
*/
|
||||||
makeOverridable = f: origArgs:
|
makeOverridable = f: origArgs:
|
||||||
let
|
let
|
||||||
ff = f origArgs;
|
result = f origArgs;
|
||||||
|
|
||||||
# Creates a functor with the same arguments as f
|
# Creates a functor with the same arguments as f
|
||||||
copyArgs = g: lib.setFunctionArgs g (lib.functionArgs 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);
|
overrideWith = newArgs: origArgs // (if lib.isFunction newArgs then newArgs origArgs else newArgs);
|
||||||
|
|
||||||
# Re-call the function but with different arguments
|
# 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
|
# Change the result of the function call by applying g to it
|
||||||
overrideResult = g: makeOverridable (copyArgs (args: g (f args))) origArgs;
|
overrideResult = g: makeOverridable (copyArgs (args: g (f args))) origArgs;
|
||||||
in
|
in
|
||||||
if builtins.isAttrs ff then (ff // {
|
if builtins.isAttrs result then
|
||||||
override = overrideArgs;
|
result // {
|
||||||
overrideDerivation = fdrv: overrideResult (x: overrideDerivation x fdrv);
|
override = overrideArgs;
|
||||||
${if ff ? overrideAttrs then "overrideAttrs" else null} = fdrv:
|
overrideDerivation = fdrv: overrideResult (x: overrideDerivation x fdrv);
|
||||||
overrideResult (x: x.overrideAttrs fdrv);
|
${if result ? 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
|
else if lib.isFunction result then
|
||||||
lib.setFunctionArgs ff (lib.functionArgs ff) // {
|
# Transform the result into a functor while propagating its arguments
|
||||||
|
lib.setFunctionArgs result (lib.functionArgs result) // {
|
||||||
override = overrideArgs;
|
override = overrideArgs;
|
||||||
}
|
}
|
||||||
else ff;
|
else result;
|
||||||
|
|
||||||
|
|
||||||
/* Call the package function in the file `fn' with the required
|
/* Call the package function in the file `fn' with the required
|
||||||
|
|
Loading…
Reference in New Issue