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

Can't override python3 in an overlay #413

Open
kjeremy opened this issue May 29, 2024 · 6 comments · May be fixed by #466
Open

Can't override python3 in an overlay #413

kjeremy opened this issue May 29, 2024 · 6 comments · May be fixed by #466

Comments

@kjeremy
Copy link
Contributor

kjeremy commented May 29, 2024

I can't seem to override python3 anymore. Previously I had an overlay that did the following:

(self: super:
python3 = super.python3.override {
  self = self.python3;
  # enable optimization etc.
  packageOverrides = ...
};)

to override some packages for cross compilation. This pattern now fails. I have a reproducer here: https://github.com/kjeremy/nix-ros-overlay-python-fail.

[jkolb@nixos:~/nix-ros-overlay-test]$ nix develop .#example
error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:9:12:
            8|
            9|   strict = derivationStrict drvAttrs;
             |            ^
           10|

       … while evaluating derivation 'nix-shell'
         whose name attribute is located at /nix/store/snp5f95xhkz89kdw9703kana3m6xfd0a-source/pkgs/stdenv/generic/make-derivation.nix:352:7

       … while evaluating attribute 'nativeBuildInputs' of derivation 'nix-shell'
         at /nix/store/snp5f95xhkz89kdw9703kana3m6xfd0a-source/pkgs/stdenv/generic/make-derivation.nix:396:7:
          395|       depsBuildBuild              = elemAt (elemAt dependencies 0) 0;
          396|       nativeBuildInputs           = elemAt (elemAt dependencies 0) 1;
             |       ^
          397|       depsBuildTarget             = elemAt (elemAt dependencies 0) 2;

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: attribute 'catkin-pkg' missing
       at /nix/store/zv36pjyxlsg6il3k6zhc1wdmgclwqqw9-source/distros/noetic/catkin/default.nix:18:41:
           17|   checkInputs = [ python3Packages.mock python3Packages.nose ];
           18|   propagatedBuildInputs = [ cmake gtest python3Packages.catkin-pkg python3Packages.empy python3Packages.nose python3Packages.setuptools ];
             |                                         ^
           19|   nativeBuildInputs = [ cmake python3Packages.setuptools ];

As an aside (hint?) in my actual project it complains about empy_3 missing.

@kjeremy
Copy link
Contributor Author

kjeremy commented May 29, 2024

I thought the following would work too but it fails to take my modifications into account.

python3 = super.python3 // {
  pkgs = super.python3.pkgs.overrideScope(pyFinal: pyPrev: {
    mypkg = pyPrev.mypkg.overrideAttrs ....
  });
};

EDIT: In this case my modifications are available under python3.pkgs but not python3Packages.

@kjeremy
Copy link
Contributor Author

kjeremy commented May 31, 2024

Okay I can work around the package issue by using pythonPackagesExtensions like the following in an overlay:

pythonPackagesExtensions = super.pythonPackagesExtensions ++ [
  (pyFinal: pyPrev: {
    pykdl = pyPrev.pykdl.overrideAttrs({ cmakeFlags ? [], ... }: {
      cmakeFlags = cmakeFlags ++ [ "-DPYTHON_EXECUTABLE=${lib.getExe self.python3.pythonOnBuildForHost}" "-DWHATEVER=1" ];
    });
  })
];

This allows my version of pykdl to be present in both python3.pkgs and python3Packages. However I still cannot override python3 in the overlay without getting the error about empy_3 missing.

@kjeremy
Copy link
Contributor Author

kjeremy commented Jun 27, 2024

@lopsided98 do you have any suggestions? This is a blocker for me.

@Pleune
Copy link

Pleune commented Jul 10, 2024

I had this same issue, and ended up just copying the pythonOverridesFor function into my flake and applying it there too. Not the best solution, but the function is short enough I did it anyways.

# from distros/distro-overlay.nix
pythonOverridesFor = with self.lib; prevPython: prevPython // {
  pkgs = prevPython.pkgs.overrideScope (pyFinal: pyPrev: {
    wxPython = pyFinal.wxPython_4_2;
    empy = pyFinal.empy_3;
};

then apply with this in your overlay.

python3 = pythonOverridesFor super.python3;

@kjeremy
Copy link
Contributor Author

kjeremy commented Jul 10, 2024

Hm. Then you add your package overrides in the implementation of pythonOverridesFor?

Edit: this approach doesn't seem to work for me. I'm still missing empy_3.

@lopsided98
Copy link
Owner

lopsided98 commented Jul 20, 2024

I switched to pythonPackagesExtensions; does this fix your issue?

@hacker1024 hacker1024 linked a pull request Sep 5, 2024 that will close this issue
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 a pull request may close this issue.

3 participants