Development shells with Nix: four quick examples
a day ago
- Nix allows using OpenCV for GoCV development without permanently installing it, avoiding system pollution and long-term maintenance of extra packages.
- The Debian approach (apt install libopencv-dev) installs over 500 packages, while Nix provides temporary, isolated environments via nix-shell or nix develop.
- Four examples demonstrate increasing complexity: interactive nix-shell -p, shell.nix for repeatability, flake.nix with pinned dependencies, and system-independent flakes using flake-utils.
- Setup requires installing Nix, enabling flakes, and setting NIX_PATH (or using NixOS which comes pre-configured).
- Nix flakes enable hermetic, reproducible development environments with locked dependency versions in flake.lock.
- For one-off experiments, nix-shell is quick; for shared/published projects, a system-independent flake.nix is recommended despite more boilerplate.