···7676 Type:
7777 makeOverridable :: (AttrSet -> a) -> AttrSet -> a
7878 */
7979- makeOverridable = f: lib.setFunctionArgs
8080- (origArgs: let
7979+ makeOverridable = f:
8080+ let
8181+ # Creates a functor with the same arguments as f
8282+ mirrorArgs = lib.mirrorFunctionArgs f;
8383+ in
8484+ mirrorArgs (origArgs:
8585+ let
8186 result = f origArgs;
82878383- # Creates a functor with the same arguments as f
8484- copyArgs = g: lib.setFunctionArgs g (lib.functionArgs f);
8588 # Changes the original arguments with (potentially a function that returns) a set of new attributes
8689 overrideWith = newArgs: origArgs // (if lib.isFunction newArgs then newArgs origArgs else newArgs);
87908891 # Re-call the function but with different arguments
8989- overrideArgs = copyArgs (newArgs: makeOverridable f (overrideWith newArgs));
9292+ overrideArgs = mirrorArgs (newArgs: makeOverridable f (overrideWith newArgs));
9093 # Change the result of the function call by applying g to it
9191- overrideResult = g: makeOverridable (copyArgs (args: g (f args))) origArgs;
9494+ overrideResult = g: makeOverridable (mirrorArgs (args: g (f args))) origArgs;
9295 in
9396 if builtins.isAttrs result then
9497 result // {
···102105 lib.setFunctionArgs result (lib.functionArgs result) // {
103106 override = overrideArgs;
104107 }
105105- else result)
106106- (lib.functionArgs f);
108108+ else result);
107109108110109111 /* Call the package function in the file `fn` with the required
···449449 (f ? __functor && isFunction (f.__functor f));
450450451451 /*
452452+ `mirrorFunctionArgs f g` creates a new function `g'` with the same behavior as `g` (`g' x == g x`)
453453+ but its function arguments mirroring `f` (`lib.functionArgs g' == lib.functionArgs f`).
454454+455455+ Type:
456456+ mirrorFunctionArgs :: (a -> b) -> (a -> c) -> (a -> c)
457457+458458+ Example:
459459+ addab = {a, b}: a + b
460460+ addab { a = 2; b = 4; }
461461+ => 6
462462+ lib.functionArgs addab
463463+ => { a = false; b = false; }
464464+ addab1 = attrs: addab attrs + 1
465465+ addab1 { a = 2; b = 4; }
466466+ => 7
467467+ lib.functionArgs addab1
468468+ => { }
469469+ addab1' = lib.mirrorFunctionArgs addab addab1
470470+ addab1' { a = 2; b = 4; }
471471+ => 7
472472+ lib.functionArgs addab1'
473473+ => { a = false; b = false; }
474474+ */
475475+ mirrorFunctionArgs =
476476+ # Function to provide the argument metadata
477477+ f:
478478+ let
479479+ fArgs = functionArgs f;
480480+ in
481481+ # Function to set the argument metadata to
482482+ g:
483483+ setFunctionArgs g fArgs;
484484+485485+ /*
452486 Turns any non-callable values into constant functions.
453487 Returns callable values as is.
454488
···13131414 # Derivations built with `buildPythonPackage` can already be overridden with `override`, `overrideAttrs`, and `overrideDerivation`.
1515 # This function introduces `overridePythonAttrs` and it overrides the call to `buildPythonPackage`.
1616- makeOverridablePythonPackage = f: origArgs:
1616+ makeOverridablePythonPackage = f: lib.mirrorFunctionArgs f (origArgs:
1717 let
1818 args = lib.fix (lib.extends
1919 (_: previousAttrs: {
···3030 overridePythonAttrs = newArgs: makeOverridablePythonPackage f (overrideWith newArgs);
3131 __functor = self: result;
3232 }
3333- else result;
3333+ else result);
34343535 mkPythonDerivation = if python.isPy3k then
3636 ./mk-python-derivation.nix