devenv
devenv copied to clipboard
`languages.python.package = pkgs.python310.withPackages (…)` does not work
Thank you for developing and maintaining this awesome project! :slightly_smiling_face:
Describe the bug
I'm trying to specify Python packages by
languages.python = {
enable = true;
package =
pkgs.python310.withPackages (ps: [
ps.xlrd
]);
};
but this does not work, i.e.
nix develop --impure --command python -c 'import xlrd; print("yeah!")'
yields
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'xlrd'
Interestingly, as also described in this comment, instead specifying
packages = with pkgs.python310Packages; [ xlrd ];
languages.python.enable = true;
does work but does not seem to be preferable due to the uncoupling of Python packages and interpreter. Or maybe I misunderstood something? Of course I could use let and friends to extract python310 somehow but that seems clunky.
To reproduce
https://gist.github.com/dpaetzel/303644fc1aa7863a4d0194c9f205b4b1
Version
I'm using Flakes.
For that to work you'll need to use https://github.com/cachix/devenv-nixpkgs for nixpkgs
For that to work you'll need to use https://github.com/cachix/devenv-nixpkgs for nixpkgs
Is this just because of the way the devenv's Python language module invokes Nixpkgs' Python wrapper via callPackage, in that if the wrapper's interface or behavior changes, that callPackage invocation might no longer have the desired effect?
I'm trying to do the same thing and set the nixpkgs input to
nixpkgs:
url: github:cachix/devenv-nixpkgs
and I now get the following error when trying to enter the shell
Updating devenv.lock ...
error:
… while updating the lock file of flake 'git+file:///Users/s/repos/myproject'
… while updating the flake input 'nixpkgs'
error:
error: flake '«github:cachix/devenv-nixpkgs/aaadd7348d76c258d788dcc6712276abb78393ab»/.devenv.flake.nix' does not exist
✖ Command produced the following output:
✔ Updating devenv.lock in 0.3s.
Error: × Command `/nix/store/y2w7cpc5b7l43hrpkzc47dgyshjcc7c0-nix-2.21-devenv/bin/nix --show-trace --extra-experimental-features nix-
│ command --extra-experimental-features flakes --option warn-dirty false --option eval-cache false --keep-going --max-jobs 4
│ flake update` failed with with exit code 1
@srounce I had the same problem, it should actually be:
inputs:
nixpkgs:
url: github:cachix/devenv-nixpkgs/rolling
But @domenkozar even using it, the original error (import error) remains. I'm using devenv directly, not in a flake.
@srounce I had the same problem, it should actually be:
inputs: nixpkgs: url: github:cachix/devenv-nixpkgs/rollingBut @domenkozar even using it, the original error (import error) remains. I'm using devenv directly, not in a flake.
I have run into the same issue trying out devenv. @domenkozar mentioned that you can put them in directly now: https://github.com/cachix/devenv/issues/601#issuecomment-2014621906
That works for some, but for others, it doesn't seem to grab all the dependencies. E.g. boto3 fails import due to a missing dependency. I manually put that in, but another dep popped up. I ended up having to specify 3 deps manually:
pkgs.python3Packages.boto3
pkgs.python3Packages.botocore
pkgs.python3Packages.jmespath
pkgs.python3Packages.dateutil
try to wrap it with additional braces it helped me to pass python.withPackages into packages = [ ... ] variable:
languages.python = {
enable = true;
package = (
pkgs.python310.withPackages (ps: [
ps.xlrd
])
);
};
But shouldn't this be syntactically the same in the Nix language? :thinking:
But shouldn't this be syntactically the same in the Nix language? 🤔
In logic - it should, but it shouldn't... IDK why.
Also confirmed, wraping with (...) helped for me when pointing language.python.package. Check it out.
Can't figure this out, I need to install pysocks before running pip/poetry and it's just impossible with devenv I guess? The whole pkgs.python3.withPackages gets ignored, I am using cachix-nixpkgs/rolling already. I tried packages = [ pkgs.python3Packages.pysocks ]; but it's not some executable, it needs to be part of site packages or the python library path or whatever, so it won't work.
This one is a hell to fix. I'll buy a whole night of beers to someone that fixes it.
@domenkozar This is properly fixed in https://github.com/NixOS/nixpkgs/pull/442540
lets wait till it merges! star it!
and the devenv can get rid of its wrapper
I understand the issue pretty well, ping if you want moreninfo
@domenkozar This is properly fixed in https://github.com/NixOS/nixpkgs/pull/442540
@domenkozar: now merged and I think devenv can now get rid of the python wrapper script or vendor the version
https://github.com/qbisi/nixpkgs/blob/python-venv/pkgs/development/interpreters/python/wrapper.nix
I guess it was vendored from nixpkgs not sure.
I really hope this PR fixes the venv and pythen intwrpreter detection problems which come with withPackages etc. lets see
@gabyx I hope we can somehow detect the new wrapper and use it instead of our own, people might still use old nixpkgs
I have a few Python projects using Devenv that pin versions of nixpkgs.
On Tue, Oct 21, 2025, 4:56 PM Domen Kožar @.***> wrote:
domenkozar left a comment (cachix/devenv#1218) https://github.com/cachix/devenv/issues/1218#issuecomment-3429960410
@gabyx https://github.com/gabyx I hope we can somehow detect the new wrapper and use it instead of our own, people might still use old nixpkgs
— Reply to this email directly, view it on GitHub https://github.com/cachix/devenv/issues/1218#issuecomment-3429960410, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAULCYNEPU47ASSL7SURBST3Y3BZXAVCNFSM6AAAAACJWSO6NWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTIMRZHE3DANBRGA . You are receiving this because you commented.Message ID: @.***>
@domenkozar:
As I understand the code in python.nix:
package = pkgs.callPackage ../../python-wrapper.nix {
python = cfg.package;
requiredPythonModules = cfg.package.pkgs.requiredPythonModules;
makeWrapperArgs =
[
"--prefix"
"LD_LIBRARY_PATH"
":"
libraries
]
++ lib.optionals pkgs.stdenv.isDarwin [
"--prefix"
"DYLD_LIBRARY_PATH"
":"
libraries
];
};
A few observations:
- One wraps the set
cfg.packagewhich is the python interpreter - The
python-wrapper.nixis vendored indevenv. - People are setting
cfg.packagetopkgs.pythonXXX.withPackageswhich is already wrapped and might be wrapped with a flawed wrapper! (old nixpkgs).
If devenv now vendors the new python-wrapper.nix from https://github.com/qbisi/nixpkgs/blob/python-venv/pkgs/development/interpreters/python/wrapper.nix
the bug might be fixed but not backwards compatible. I dont know how one can easily detect package = pkgs.pythonXXX.withPackages ... and exchange the "wrapping"??
Would it make sense to have
languages.python = {
withPackages = (p: [...]);
package = pkgs.python313;
}
and require that cfg.package is a single python interpreter and not wrapped (can it be detected)?