Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

haskell: preserve overrideScope on override #9336

Closed
wants to merge 2 commits into from

Conversation

bennofs
Copy link
Contributor

@bennofs bennofs commented Aug 19, 2015

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 #7953

@peti can you test that this doesn't lead to unexpected side effects, I'm unsure about the performance implications of the change.

@rasendubi
Copy link
Member

(triage) As far as I can tell, it's still relevant.

@peti would you like to review this?

@peti
Copy link
Member

peti commented Jul 26, 2016

I'm not sure what to do with this patch. It does a problem we have (albeit not an urgent one), so we want to merge, I suppose. On the other hand, the patch duplicates code that we probably don't want to duplicate. Instead, the proper implementation of callPackageWith should be refactord/extended. Doing that is a bit of an effort, though, and I don't see anyone who's willing to dedicate that effort right now. So it seems like we're stuck.

@bennofs
Copy link
Contributor Author

bennofs commented Jul 28, 2016

I don't think that the duplicated code should be of much concern: it is only 3 lines that are duplicated (the drv and auto let bindings + the code for the in). Anyway, I rebased the branch to be compatible with master.

@domenkozar
Copy link
Member

@bennofs can you verify that master still needs this fix?

@bennofs
Copy link
Contributor Author

bennofs commented Feb 27, 2017

@domenkozar yes still necessary:

d-cube:/c/nixpkgs (master=) nix-build -E 'with (import ./. {}); (haskellPackages.acme-realworld.override {}).overrideScope (self: super: {})'
error: attribute ‘overrideScope’ missing, at (string):1:23

@peti
Copy link
Member

peti commented Feb 28, 2017

@bennofs, your example was not fixed by #22613?

@bennofs
Copy link
Contributor Author

bennofs commented Feb 28, 2017

@peti yes still:

 $ git pull; nix-build -E 'with (import ./. {}); (haskellPackages.acme-realworld.override {}).overrideScope (self: super: {})'
Already up-to-date.
error: attribute ‘overrideScope’ missing, at (string):1:23

How should that patch fix this? The issue is that overrideScope ìs not added "under" callPackage, but instead is added directly to the result of callPackage. So callPackage doesn't know about the extra attribute, and the override function will no re-add it after re-calling the package with new arguments,

@peti
Copy link
Member

peti commented Feb 28, 2017 via email

@bennofs
Copy link
Contributor Author

bennofs commented Apr 21, 2017

@peti so any idea how we progress with this? it's currently one of the oldest PRs on the nixpkgs repo, and I don't think that more time will change the situation. So it seems we have three options:

  1. leave the code as is. I'm not sure how common it is to want to call overrideScope after override, but it is probably bad if you want to overrideScope a pkg that has overrides defined by some of the standard -configuration overrides.
  2. copy 3 lines from customization.nix and adapt them
  3. change customization.nix to support this, which might break other parts of nixpkgs in unforseen ways (will need lots of reviews for sure)

@peti
Copy link
Member

peti commented Apr 24, 2017

@bennofs, I think option (2) is the best solution. The code duplication is unfortunate, but I don't see any reasonable way around it. Would you mind pushing an updated version of this patch that fixes the merge conflicts? I'll be happy to merge the PR then.

@peti
Copy link
Member

peti commented Apr 24, 2017

Merged to haskell-updates for test-building in b39964cec5d505c00196ff0983b9fe008aac8401.

@bennofs
Copy link
Contributor Author

bennofs commented Apr 24, 2017

@peti I rebased to master and force-pushed.

edit: oh I see you already noticed! 👍

@peti
Copy link
Member

peti commented Apr 25, 2017

Something isn't right: http://hydra.nixos.org/jobset/nixpkgs/haskell-updates. After b39964cec5d505c00196ff0983b9fe008aac8401 was added to the branch, stack is broken, apparently because the override

  stack = super.stack.overrideScope (self: super: {
    store-core = self.store-core_0_3;
    store = self.store_0_3_1;
  });

no longer works as before.

@bennofs
Copy link
Contributor Author

bennofs commented Apr 25, 2017

@peti that is... weird. I will investigate.

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 #7953.
Closes #9336.
@bennofs
Copy link
Contributor Author

bennofs commented Apr 25, 2017

@peti fixed. stack compiles now. I added some docs that explain the the trickiness here.

@peti peti closed this in 731e0fa Apr 25, 2017
@peti peti deleted the haskell-fix-override branch April 25, 2017 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Haskell packages lose theire "overrideScope" attribute after a normal "override"
4 participants