summary refs log tree commit diff
diff options
context:
space:
mode:
authorSilvan Mosberger <infinisil@icloud.com>2019-09-05 00:13:24 +0200
committerSilvan Mosberger <infinisil@icloud.com>2019-09-05 00:56:39 +0200
commitd54bdf5504cfe43937e4cfc1f3e03ad621f74b87 (patch)
tree72b9d8586dff57f6e2148666a7d8c3c60a877f5e
parente140d709c43ab25d993c5c78b4e01aee754b49af (diff)
downloadnixpkgs-d54bdf5504cfe43937e4cfc1f3e03ad621f74b87.tar
nixpkgs-d54bdf5504cfe43937e4cfc1f3e03ad621f74b87.tar.gz
nixpkgs-d54bdf5504cfe43937e4cfc1f3e03ad621f74b87.tar.bz2
nixpkgs-d54bdf5504cfe43937e4cfc1f3e03ad621f74b87.tar.lz
nixpkgs-d54bdf5504cfe43937e4cfc1f3e03ad621f74b87.tar.xz
nixpkgs-d54bdf5504cfe43937e4cfc1f3e03ad621f74b87.tar.zst
nixpkgs-d54bdf5504cfe43937e4cfc1f3e03ad621f74b87.zip
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; }
-rw-r--r--lib/customisation.nix6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/customisation.nix b/lib/customisation.nix
index 21bab1ab4bc..09d7fbf74b0 100644
--- a/lib/customisation.nix
+++ b/lib/customisation.nix
@@ -67,12 +67,14 @@ rec {
   makeOverridable = f: origArgs:
     let
       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);
 
       # 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
-      overrideResult = g: makeOverridable (args: g (f args)) origArgs;
+      overrideResult = g: makeOverridable (copyArgs (args: g (f args))) origArgs;
     in
       if builtins.isAttrs ff then (ff // {
         override = overrideArgs;