mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-12 04:35:41 +03:00
lib/makeOverridable: Propagate function arguments to override functions
This allows querying the arguments you can .override: nix-repl> lib.functionArgs pkgs.hello.override { fetchurl = false; stdenv = false; }
This commit is contained in:
parent
e140d709c4
commit
d54bdf5504
1 changed files with 4 additions and 2 deletions
|
@ -67,12 +67,14 @@ rec {
|
||||||
makeOverridable = f: origArgs:
|
makeOverridable = f: origArgs:
|
||||||
let
|
let
|
||||||
ff = f origArgs;
|
ff = f origArgs;
|
||||||
|
# Creates a functor with the same arguments as f
|
||||||
|
copyArgs = g: lib.setFunctionArgs g (lib.functionArgs f);
|
||||||
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
|
||||||
overrideArgs = newArgs: makeOverridable f (overrideWith newArgs);
|
overrideArgs = copyArgs (newArgs: makeOverridable f (overrideWith newArgs));
|
||||||
# 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 (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 ff then (ff // {
|
||||||
override = overrideArgs;
|
override = overrideArgs;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue