git.iko.soy/typeable/nixpkgs
on master help sign in
haskell: preserve overrideScope on override

We want code such as `(pkg.override {}).overrideScope (self: super: {})` to work. This didn't work before, since `override` will call the original package again, and the attribute `overideScope`, which `callPackageWithScope` added, wasn't added again. The fix for this is to modify the package function itself to include the `callPackageWithScope` attribute, so it'll be re-added whenever the function is overriden for with arguments. There is a small problem here though: since callPackage uses some magic (`builtins.functionArgs`) to determine the auto-arguments of a function, we can't just write `callPackageWith scope drvScope`, since `builtins.functionArgs drvScope` will be `{}`. To fix this, we implement our own `callPackageWith`. Fixes https://github.com/NixOS/nixpkgs/issues/7953. Closes https://github.com/NixOS/nixpkgs/pull/9336.

commit731e0fa7423ae34cf25bf967c90228ec7ea99e10 authorBenno Fünfstück <benno.fuenfstueck@gmail.com> dateWed 19 Aug 2015, 11:23 (11 years ago) parent9b74549
1 file changed+17−3
pkgs/development/haskell-modules/make-package-set.nix+17−3
pkgs/development/haskell-modules/make-package-set.nix+17−3
@@ -44,9 +44,23 @@ self: let
4444
4545 mkDerivation = makeOverridable mkDerivationImpl;
4646
47− callPackageWithScope = scope: drv: args: (stdenv.lib.callPackageWith scope drv args) // {
48− overrideScope = f: callPackageWithScope (mkScope (fix' (extends f scope.__unfix__))) drv args;
49− };
47+ callPackageWithScope = scope: fn: manualArgs:
48+ let
49+ # this code is copied from callPackage in lib/customisation.nix
50+ #
51+ # we cannot use `callPackage` here because we want to call `makeOverridable`
52+ # on `drvScope` (we cannot add `overrideScope` after calling `callPackage` because then it is
53+ # lost on `.override`) but determine the auto-args based on `drv` (the problem here
54+ # is that nix has no way to "passthrough" args while preserving the reflection
55+ # info that callPackage uses to determine the arguments).
56+ drv = if builtins.isFunction fn then fn else import fn;
57+ auto = builtins.intersectAttrs (builtins.functionArgs drv) scope;
58+ drvScope = allArgs: drv allArgs // {
59+ overrideScope = f:
60+ let newScope = mkScope (fix' (extends f scope.__unfix__));
61+ in callPackageWithScope newScope drv manualArgs;
62+ };
63+ in stdenv.lib.makeOverridable drvScope (auto // manualArgs);
5064
5165 mkScope = scope: pkgs // pkgs.xorg // pkgs.gnome2 // scope;
5266 defaultScope = mkScope self;