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

Use composeExtensions to preserve existing Python package overrides #192

Merged
merged 1 commit into from
May 14, 2022

Conversation

mcwitt
Copy link
Contributor

@mcwitt mcwitt commented May 13, 2022

Resolves #183

This PR addresses the scenario where the qchem overlay is applied after another overlay that overrides Python packages. Currently, the previously-applied overrides will be lost due to Python overrides not composing by default (NixOS/nixpkgs#44426).

The following is a minimal reproduction:

let
  qchemOverlay = import ./overlay.nix;

  myOverlay = _: prev: {
    python3 = prev.python3.override {
      packageOverrides = (_: _: { foo = 42; });
    };
  };

  pkgs = import <nixpkgs> {
    overlays = [
      myOverlay
      qchemOverlay
    ];
  };
in
pkgs.qchem.python3.pkgs.foo

Currently, this expression fails to evaluate:

$ nix eval -f test.nix
error: attribute 'foo' missing

This PR modifies the qchem overlay to preserve existing overrides, using the variant of override that accepts a function from old to new overrides and lib.composeExtensions. This is similar to the approach used in tweag/jupyterWith.

@markuskowa markuskowa merged commit 175598e into Nix-QChem:master May 14, 2022
@markuskowa
Copy link
Collaborator

Currently, this expression fails to evaluate:

$ nix eval -f test.nix
error: attribute 'foo' missing

nix-build test.nix works with this (e.g. use a real package):

let
  qchemOverlay = import ./overlay.nix;

  myOverlay = _: prev: {
    python3 = prev.python3.override {
      packageOverrides = (_: p: { foo = p.numpy; });
    };
  };

  pkgs = import <nixpkgs> {
    overlays = [
      myOverlay
      qchemOverlay
    ];
  };
in
pkgs.qchem.python3.pkgs.foo

@mcwitt
Copy link
Contributor Author

mcwitt commented May 14, 2022

nix-build test.nix works with this (e.g. use a real package):

@markuskowa ah, that's a more realistic reproduction!

Just to clarify, I assume you mean this works only on the PR branch? (Before the patch, this also fails for me, as expected)

@markuskowa
Copy link
Collaborator

markuskowa commented May 16, 2022

Yes, it works on the PR branch, and now also on master.
Thanks for submitting this patch!

@mcwitt mcwitt deleted the compose-python-overrides branch May 17, 2022 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Workaround for Python packageOverrides
2 participants