On Nix(OS) can i setup a python development environment from requirements files without ruffling the package managers feathers?
When ready to create a wheel, python -m build, how does Nix(OS) want the python package to be built to gain all the benefits of Nix(OS) build reproducibility?
If you just want to quickly create a local python develop environment on the side using Python module metadata, installing uv from nixpkgs, and enabling nix-ld to run pre-compiled binaries from PyPI keeps things simple, and replicating the same virtual python environment workflow you to have on any other distribution:
If you wanted to package a python module for nix or for proper distribution via nixpkgs, you’d want to add a nix derivation file that encapsulates all the inputs, i.e. software building materials (SBOM). There are existing nix library functions that can automate most of the packaging, not unlike Debian macros:
The second approach is more rigorous, and combined with something like flakes for pinning the exact hash for all inputs via lock file ensures reproducibility, like when sharing with other nix users. While as the first approach is more subject to your current system, i.e. linking to whatever system wide libraries are presently installed, but it’s less upfront effort to reuse existing python-package-managers than to nixify everything.
Finally got to a Python question
On Nix(OS) can i setup a python development environment from requirements files without ruffling the package managers feathers?
When ready to create a wheel,
python -m build
, how does Nix(OS) want the python package to be built to gain all the benefits of Nix(OS) build reproducibility?If you just want to quickly create a local python develop environment on the side using Python module metadata, installing
uv
from nixpkgs, and enablingnix-ld
to run pre-compiled binaries from PyPI keeps things simple, and replicating the same virtual python environment workflow you to have on any other distribution:https://discourse.nixos.org/t/i-want-understanding-nix-packages-and-flake-basics/67365/3
If you wanted to package a python module for nix or for proper distribution via nixpkgs, you’d want to add a nix derivation file that encapsulates all the inputs, i.e. software building materials (SBOM). There are existing nix library functions that can automate most of the packaging, not unlike Debian macros:
https://wiki.nixos.org/wiki/Python
The second approach is more rigorous, and combined with something like flakes for pinning the exact hash for all inputs via lock file ensures reproducibility, like when sharing with other nix users. While as the first approach is more subject to your current system, i.e. linking to whatever system wide libraries are presently installed, but it’s less upfront effort to reuse existing python-package-managers than to nixify everything.