1
nix-env -iA nixpkgs.python311

it works

But when i do a

nix-shell -p nixpkgs.python311

or a

nix-shell -p python3-3.11.1

visibly there are problem in the name and arg

nix-shell -p python3-3.11.1 error: undefined variable 'python3-3'

   at «string»:1:107:
    1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [

(python3-3.11.1) ]; } "" | ^ (use '--show-trace' to show detailed location information)

Regards

1 Answers1

1

If you want to pass an arbitrary Nix expression to nix-shell -p, put it in parenthesis:

nix-shell -p '((import <nixpkgs> {}).python311)'

Anything you could append to nix-env -iA nixpkgs. you should be able to append in place of python311 above. It also can be used for things like:

nix-shell -p \
  '((import <nixpkgs> {}).python311.withPackages (p: [p.lxml p.pyyaml]))'

...to provide Python 3.11 with lxml and PyYAML installed.

Charles Duffy
  • 1,732
  • 15
  • 22