Commit 1a14dc6e authored by sternenseemann's avatar sternenseemann
Browse files

haskellPackages.callPackage: preserve functionArgs

Our wrapper for lib.makeOverridable wraps the underlying function which
means the wrapper function doesn't replicate the same set pattern.
We can, however, tell lib.functionArgs about the permissible arguments
by making the function a functor and adding __functionArgs.
parent 0b96957f
Loading
Loading
Loading
Loading
+24 −18
Original line number Diff line number Diff line
@@ -107,14 +107,17 @@ let
      # is that nix has no way to "passthrough" args while preserving the reflection
      # info that callPackage uses to determine the arguments).
      drv = if lib.isFunction fn then fn else import fn;
      auto = builtins.intersectAttrs (lib.functionArgs drv) scope;
      drvFunctionArgs = lib.functionArgs drv;
      auto = builtins.intersectAttrs drvFunctionArgs scope;

      # Converts a returned function to a functor attribute set if necessary
      ensureAttrs = v: if builtins.isFunction v then { __functor = _: v; } else v;

      # this wraps the `drv` function to add `scope` and `overrideScope` to the result.
      drvScope =
        allArgs:
      # it's a functor, so that we can pass through `functionArgs`
      drvScope = {
        __functor =
          _: allArgs:
          ensureAttrs (drv allArgs)
          // {
            inherit scope;
@@ -130,6 +133,9 @@ let
              # nothing.
              callPackageWithScope newScope drv manualArgs;
          };
        # `drvScope` accepts the same arguments as `drv`
        __functionArgs = drvFunctionArgs;
      };
    in
    lib.makeOverridable drvScope (auto // manualArgs);