When I try to install pytest for python37 it fails
nix-shell -p 'python37.withPackages(ps: with ps; [pytest])'
...
ERROR: Could not find a version that satisfies the requirement importlib-metadata; python_version < "3.8" (from setuptools-scm) (from versions: none)
ERROR: No matching distribution found for importlib-metadata; python_version < "3.8"
Do you have any idea why it is not the python37 pytest that is used?
Ok, thanks a lot. Is there a way I should have known that? As a new user I thought that all packages available in <nixpkgs> are maintained until removed.
error: attribute 'currentSystem' missing
at «string»:1:111:
1| with builtins.getFlake "github:NixOS/nixpkgs/20dd1e678299aae83735f1af5d1dcd80de22da5f"; with legacyPackages.${builtins.currentSystem}; python37.withPackages (ps: with ps; [ pytest ])
Thanks, you’re right. Stupid of me. Now I know that
nix shell nixpkgs/20dd1e678299aae83735f1af5d1dcd80de22da5f#hello -c hello
nix shell --expr 'with builtins.getFlake "github:NixOS/nixpkgs/20dd1e678299aae83735f1af5d1dcd80de22da5f"; with legacyPackages.x86_64-linux; python37.withPackages (ps: with ps; [ pytest ])'
works.
Two questions
Is it correct, that there is no way to shorten the last command?
running
$ nix registry list
system flake:nixpkgs path:/nix/store/7xlnfnx4pc3bv0kp719jr1r8jbsxkv54-source?lastModified=1664989420&narHash=sha256-Q8IxomUjjmewsoJgO3htkXLfCckQ7HkDJ%2fZhdYVf%2ffA=&rev=37bd39839acf99c5b738319f42478296f827f274
global flake:nixpkgs github:NixOS/nixpkgs/nixpkgs-unstable
How do nix know that nix shell nixpkgs/20dd1e6 should be interpreted as the global flake? In NIX_PATH, nixpkgs points to /nix/store/7x...
I’m not seeing where you were being stupid and I’m sorry if I made you feel that way.
I’m also just learning the concept of flakes and from what I have so far I can only say I would pin the commit you have:
user flake:nixpkgs-mypin github:NixOS/nixpkgs/nixpkgs-unstable
user github:NixOS/nixpkgs/nixpkgs-unstable github:NixOS/nixpkgs/20dd1e678299aae83735f1af5d1dcd80de22da5f
The expression with getFlake would condense into (for x86_64-linux): nix shell --expr 'with builtins.getFlake "nixpkgs-mypin"; with legacyPackages.x86_64-linux; python38.withPackages (ps: with ps; [ pytest ])'.
On the other hand if you’re already in the process of declaring a pin via registry the concise contains-all-info-needed command line call might not have that much importance anyway and you would be better off writing a nix expression in a file ?
Regarding the <something> approach from what I know you need -I at some point as you said yourself, can test it via nix repl -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/20dd1e678299aae83735f1af5d1dcd80de22da5f.tar.gz and nix-repl> <nixpkgs>. This so answer explains that.
You sure could then nix shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/20dd1e678299aae83735f1af5d1dcd80de22da5f.tar.gz --expr 'with import <nixpkgs> {}; python38.withPackages (ps: with ps; [ pytest ])'.