Python: Difference between revisions

Samuela (talk | contribs)
Samuela (talk | contribs)
Follow best practices by pinning the nixpkgs commit in shell.nix
Line 11: Line 11:
# shell.nix
# shell.nix
let
let
   pkgs = import <nixpkgs> {};
  # We pin to a specific nixpkgs commit for reproducibility.
  # Last updated: 2024-04-29. Check for new commits at https://status.nixos.org.
   pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/cf8cc1201be8bc71b7cbbbdaf349b22f4f99c7ae.tar.gz") {};
in pkgs.mkShell {
in pkgs.mkShell {
   packages = [
   packages = [
Line 28: Line 30:


Once you have picked the Python packages you want, run <code>nix-shell</code> (or <code>nix develop -f shell.nix</code>)  to build the Python environment and enter it. Once in the environment Python will be available in your PATH, so you can run eg. <code>python --version</code>.
Once you have picked the Python packages you want, run <code>nix-shell</code> (or <code>nix develop -f shell.nix</code>)  to build the Python environment and enter it. Once in the environment Python will be available in your PATH, so you can run eg. <code>python --version</code>.
As a word of warning, using <code>pkgs = import <nixpkgs> {};</code> as in the snippet above (line 3) will result in a non-reproducible environment. Use Nixpkgs pinning or Nix Flakes to make your environment reproducible.


==== Using a Python packages not in Nixpkgs ====
==== Using a Python packages not in Nixpkgs ====