···76 Type:
77 makeOverridable :: (AttrSet -> a) -> AttrSet -> a
78 */
79- makeOverridable = f: lib.setFunctionArgs
80- (origArgs: let
0000081 result = f origArgs;
8283- # Creates a functor with the same arguments as f
84- copyArgs = g: lib.setFunctionArgs g (lib.functionArgs f);
85 # Changes the original arguments with (potentially a function that returns) a set of new attributes
86 overrideWith = newArgs: origArgs // (if lib.isFunction newArgs then newArgs origArgs else newArgs);
8788 # Re-call the function but with different arguments
89- overrideArgs = copyArgs (newArgs: makeOverridable f (overrideWith newArgs));
90 # Change the result of the function call by applying g to it
91- overrideResult = g: makeOverridable (copyArgs (args: g (f args))) origArgs;
92 in
93 if builtins.isAttrs result then
94 result // {
···102 lib.setFunctionArgs result (lib.functionArgs result) // {
103 override = overrideArgs;
104 }
105- else result)
106- (lib.functionArgs f);
107108109 /* Call the package function in the file `fn` with the required
···76 Type:
77 makeOverridable :: (AttrSet -> a) -> AttrSet -> a
78 */
79+ makeOverridable = f:
80+ let
81+ # Creates a functor with the same arguments as f
82+ mirrorArgs = lib.mirrorFunctionArgs f;
83+ in
84+ mirrorArgs (origArgs:
85+ let
86 result = f origArgs;
870088 # Changes the original arguments with (potentially a function that returns) a set of new attributes
89 overrideWith = newArgs: origArgs // (if lib.isFunction newArgs then newArgs origArgs else newArgs);
9091 # Re-call the function but with different arguments
92+ overrideArgs = mirrorArgs (newArgs: makeOverridable f (overrideWith newArgs));
93 # Change the result of the function call by applying g to it
94+ overrideResult = g: makeOverridable (mirrorArgs (args: g (f args))) origArgs;
95 in
96 if builtins.isAttrs result then
97 result // {
···105 lib.setFunctionArgs result (lib.functionArgs result) // {
106 override = overrideArgs;
107 }
108+ else result);
0109110111 /* Call the package function in the file `fn` with the required
···449 (f ? __functor && isFunction (f.__functor f));
450451 /*
0000000000000000000000000000000000452 Turns any non-callable values into constant functions.
453 Returns callable values as is.
454
···449 (f ? __functor && isFunction (f.__functor f));
450451 /*
452+ `mirrorFunctionArgs f g` creates a new function `g'` with the same behavior as `g` (`g' x == g x`)
453+ but its function arguments mirroring `f` (`lib.functionArgs g' == lib.functionArgs f`).
454+455+ Type:
456+ mirrorFunctionArgs :: (a -> b) -> (a -> c) -> (a -> c)
457+458+ Example:
459+ addab = {a, b}: a + b
460+ addab { a = 2; b = 4; }
461+ => 6
462+ lib.functionArgs addab
463+ => { a = false; b = false; }
464+ addab1 = attrs: addab attrs + 1
465+ addab1 { a = 2; b = 4; }
466+ => 7
467+ lib.functionArgs addab1
468+ => { }
469+ addab1' = lib.mirrorFunctionArgs addab addab1
470+ addab1' { a = 2; b = 4; }
471+ => 7
472+ lib.functionArgs addab1'
473+ => { a = false; b = false; }
474+ */
475+ mirrorFunctionArgs =
476+ # Function to provide the argument metadata
477+ f:
478+ let
479+ fArgs = functionArgs f;
480+ in
481+ # Function to set the argument metadata to
482+ g:
483+ setFunctionArgs g fArgs;
484+485+ /*
486 Turns any non-callable values into constant functions.
487 Returns callable values as is.
488
···1314 # Derivations built with `buildPythonPackage` can already be overridden with `override`, `overrideAttrs`, and `overrideDerivation`.
15 # This function introduces `overridePythonAttrs` and it overrides the call to `buildPythonPackage`.
16- makeOverridablePythonPackage = f: origArgs:
17 let
18 args = lib.fix (lib.extends
19 (_: previousAttrs: {
···30 overridePythonAttrs = newArgs: makeOverridablePythonPackage f (overrideWith newArgs);
31 __functor = self: result;
32 }
33- else result;
3435 mkPythonDerivation = if python.isPy3k then
36 ./mk-python-derivation.nix
···1314 # Derivations built with `buildPythonPackage` can already be overridden with `override`, `overrideAttrs`, and `overrideDerivation`.
15 # This function introduces `overridePythonAttrs` and it overrides the call to `buildPythonPackage`.
16+ makeOverridablePythonPackage = f: lib.mirrorFunctionArgs f (origArgs:
17 let
18 args = lib.fix (lib.extends
19 (_: previousAttrs: {
···30 overridePythonAttrs = newArgs: makeOverridablePythonPackage f (overrideWith newArgs);
31 __functor = self: result;
32 }
33+ else result);
3435 mkPythonDerivation = if python.isPy3k then
36 ./mk-python-derivation.nix