git.iko.soy/typeable/nixpkgs
on master help sign in
haskell: add more callPackageWithScope docs
commit6b36d26a24308e23ee80ebfeff0b61e147fb92c7 authorBenno Fünfstück <benno.fuenfstueck@gmail.com> dateTue 25 Apr 2017, 14:44 (10 years ago) parent731e0fa
1 file changed+12
pkgs/development/haskell-modules/make-package-set.nix+12
pkgs/development/haskell-modules/make-package-set.nix+12
@@ -44,6 +44,11 @@ self: let
4444
4545 mkDerivation = makeOverridable mkDerivationImpl;
4646
47+ # manualArgs are the arguments that were explictly passed to `callPackage`, like:
48+ #
49+ # callPackage foo { bar = null; };
50+ #
51+ # here `bar` is a manual argument.
4752 callPackageWithScope = scope: fn: manualArgs:
4853 let
4954 # this code is copied from callPackage in lib/customisation.nix
@@ -55,9 +60,16 @@ self: let
5560 # info that callPackage uses to determine the arguments).
5661 drv = if builtins.isFunction fn then fn else import fn;
5762 auto = builtins.intersectAttrs (builtins.functionArgs drv) scope;
63+
64+ # this wraps the `drv` function to add a `overrideScope` function to the result.
5865 drvScope = allArgs: drv allArgs // {
5966 overrideScope = f:
6067 let newScope = mkScope (fix' (extends f scope.__unfix__));
68+ # note that we have to be careful here: `allArgs` includes the auto-arguments that
69+ # weren't manually specified. If we would just pass `allArgs` to the recursive call here,
70+ # then we wouldn't look up any packages in the scope in the next interation, because it
71+ # appears as if all arguments were already manually passed, so the scope change would do
72+ # nothing.
6173 in callPackageWithScope newScope drv manualArgs;
6274 };
6375 in stdenv.lib.makeOverridable drvScope (auto // manualArgs);