Modern equivalent to nix-shell -p expression?

To enter a shell with python 3 + funcy, I do:

nix-shell -p 'python3.withPackages(ps:[ps.funcy])'

What would be the equivalent in modern nix? None of these work:

➤ nix shell nixpkgs --expr 'python3.withPackages(ps: [ps.funcy])'
error: undefined variable 'python3'

       at «string»:1:1:

            1| python3.withPackages(ps: [ps.funcy])
             | ^

➤ nix shell -f '<nixpkgs>' --expr 'python3.withPackages(ps: [ps.funcy])'
error: '--file' and '--expr' are exclusive
Try 'nix --help' for more information.

➤ nix shell 'nixpkgs#python3.withPackages(ps: [ps.funcy])'
error: 'nixpkgs#python3.withPackages(ps: [ps.funcy])' is not a valid URL
1 Like

somewhere in another thread here i’ve learnt this magic:
nix shell --impure --expr 'with builtins.getFlake "nixpkgs"; with legacyPackages.${builtins.currentSystem}; python3.withPackages(ps: [ps.funcy])'

Just rolls off your tounge… :slight_smile:

it doesn’t seem that there is a full feature replacement of nix-shell with new nix commands, so i’ve just added “nixpkgs” to NIX_PATH to reference the version of nixpkgs my system is built from (in flake), and deleted all channels. So this allows using “legacy” nix-shell with flake-based system

4 Likes