I’m facing some issues in nix-shell
where my env seems to arbitrarily choose HM or system installed binaries over the ones in my shell. This is especially problematic for “sub-envs” such as the python
one below, since if a script simply calls e.g. python3
I can get the global one instead of the one in my shell (which is missing the necessary py-modules):
{ pkgs ? import <nixpkgs> { config.documentation = { man.enable = false; doc.enable = false; info.enable = false; }; }
, unstable ? import <unstable> { config.documentation = { man.enable = false; doc.enable = false; info.enable = false; }; }
}:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [
(texlive.combine { inherit (texlive)
scheme-small xcolor koma-script nth marvosym fontawesome multirow placeins enumitem tcolorbox
lualatex-math environ lastpage titlesec advdate
collection-langgerman collection-langenglish
;})
]
++ (with unstable; [
pandoc-drawio-filter pandoc-include pandoc-plantuml-filter pandoc-lua-filters
(haskellPackages.ghcWithPackages (h: with h; [
pandoc pandoc-crossref pandoc-include-code pandoc-plot
]))
(python310.withPackages (p: with p; [ pandoc-xnos openpyxl ]))
(ruby_3_1.withPackages (p: with p; [ pandocomatic ]))
]);
# SOURCE_DATE needed for LaTeX \today to function!
shellHook = ''
export SOURCE_DATE_EPOCH="$(date +%s)"
export FORCE_SOURCE_DATE=1
'';
}
I know I could set PATH
explicitly in shellHook
with PATH=${pkgs.somepkg}/bin:...:$PATH
but that’s quite impractical, since obviously in an impure shell the buildInputs
should always have priority over user-/system-wide values (and it would introduce huge amounts of boilerplate for each shell.nix
).
FWIW I cannot reproduce this.
$ grep PATH= $(nix-build -E "let pkgs = import <nixpkgs-unstable> {}; in pkgs.mkShell { packages = [(pkgs.python310.withPackages (pythonPkgs: [ pythonPkgs.flask ]))] ; }") 5s
declare -x HOST_PATH="/nix/store/a99i3wf2ig85clra7rs5kgi46s46xvwc-coreutils-9.0/bin:/nix/store/aw9sfhxan3p1kzxrm5m413i9xrqh4885-findutils-4.9.0/bin:/nix/store/6csi1dq3fbjn218pcc5453f5ch2hpcap-diffutils-3.8/bin:/nix/store/2clbzz8170g3rcbc6d1aq1gdkph85ji8-gnused-4.8/bin:/nix/store/9hnir0nnhgr01nprclv5c1fjzl43kxmh-gnugrep-3.7/bin:/nix/store/73l0b2xl5l3gq2zggnwxh2gljgbv5qaf-gawk-5.1.1/bin:/nix/store/9ia80kzgnizdj7ninwqgswqw4fjk3kb9-gnutar-1.34/bin:/nix/store/fnc43i0012b3l7lpbi3wzaj4wlgllv8h-gzip-1.12/bin:/nix/store/rpvgpi16f0gxm9hpvvsk2ag2w5zvhycp-bzip2-1.0.6.0.2-bin/bin:/nix/store/pi4miqrq2gpcs8qs9wp6vcsm4i6j514b-gnumake-4.3/bin:/nix/store/14lypyys4gfcl982rjddxa6jg7msqz9q-bash-5.1-p16/bin:/nix/store/cgz6wqipjx24b5mqvjrm5kxb105gv14c-patch-2.7.6/bin:/nix/store/5arbmmyiadd8m0s9bq9di8xxz5lb037b-xz-5.2.5-bin/bin"
declare -x PATH="/nix/store/hbk3zr6xvphsz4ipmyyakz5dnw2qgfln-python3-3.10.4-env/bin:/nix/store/ibb2bhi5by0vlkj2lfc3f0rklaf36692-patchelf-0.14.5/bin:/nix/store/gfr4ljdlr1wplc01j4fchw4w9x3lfvv9-gcc-wrapper-11.3.0/bin:/nix/store/ck3jkdhlvqznybcq4s4s3hp2qyqp5kkm-gcc-11.3.0/bin:/nix/store/vinqsa9jxqjg590i9rxy1d6ikvn3zv0g-glibc-2.34-210-bin/bin:/nix/store/a99i3wf2ig85clra7rs5kgi46s46xvwc-coreutils-9.0/bin:/nix/store/nhv0j3rsa1qirwgw9mym03lbbxy1almv-binutils-wrapper-2.38/bin:/nix/store/3fqi6nigj8dkbvjnw8y4dy59gkq8vsj4-binutils-2.38/bin:/nix/store/a99i3wf2ig85clra7rs5kgi46s46xvwc-coreutils-9.0/bin:/nix/store/aw9sfhxan3p1kzxrm5m413i9xrqh4885-findutils-4.9.0/bin:/nix/store/6csi1dq3fbjn218pcc5453f5ch2hpcap-diffutils-3.8/bin:/nix/store/2clbzz8170g3rcbc6d1aq1gdkph85ji8-gnused-4.8/bin:/nix/store/9hnir0nnhgr01nprclv5c1fjzl43kxmh-gnugrep-3.7/bin:/nix/store/73l0b2xl5l3gq2zggnwxh2gljgbv5qaf-gawk-5.1.1/bin:/nix/store/9ia80kzgnizdj7ninwqgswqw4fjk3kb9-gnutar-1.34/bin:/nix/store/fnc43i0012b3l7lpbi3wzaj4wlgllv8h-gzip-1.12/bin:/nix/store/rpvgpi16f0gxm9hpvvsk2ag2w5zvhycp-bzip2-1.0.6.0.2-bin/bin:/nix/store/pi4miqrq2gpcs8qs9wp6vcsm4i6j514b-gnumake-4.3/bin:/nix/store/14lypyys4gfcl982rjddxa6jg7msqz9q-bash-5.1-p16/bin:/nix/store/cgz6wqipjx24b5mqvjrm5kxb105gv14c-patch-2.7.6/bin:/nix/store/5arbmmyiadd8m0s9bq9di8xxz5lb037b-xz-5.2.5-bin/bin"
Is it possible your shell setup (e.g., bashrc) prepends to the path when the shell is started? Perhaps nix-shell --command "bash -x"
might help.