NixOS and Nix functional package manager
Use Cases
Section titled “Use Cases”-
Unique package installations, trying out packages, multiple dependencies and version
-
Multiple versions of packages, complete with dependencies
- Reuse of common package versions
-
Multiple user support
-
Reproducible build environments / packages / operating system
- Defined by configuration file
- Avoid long reinstall and config
- Environments can include only declared packages or merge of declared packages and user’s own environment
- Declared environment setting
- Dockerfiles
- Package files
- Defined by configuration file
-
Roll back easy with generations
-
Good for reproducibility, stability, frequent system changes
Disadvantages
Section titled “Disadvantages”- Requires command line and configuration files
Nix as a Package Manager
Section titled “Nix as a Package Manager”How to use NixOS package manager
Examples
- Install using Nix shell script
Supports
Section titled “Supports”- Atomic upgrades and rollbacks
- Nix store, stores packages
- Garbage collection
- Functional package language
- Nix expressions describe everything that goes into a package build action (a derivation)
- Linux and macOS
- NixOS is a Linux distribution using Nix for package management and
system configuration like
/etcfiles
- Install using quick start instructions
Environment Variables
Section titled “Environment Variables”- PATH should include nix binaries
- During install, Nix installer will use proxy environment variables
Commands
Section titled “Commands”# List all packages available in installed channels (repositories)nix-env -qaP
# Install packagenix-env -iA nixpkgs.<package> # Test packages with `which <package>`
# uninstall packagenix-env -e <package>
# Build an download dependencies in your Nix store and start bash shell with required environment variablesnix-shell# Install package and go into shell with it, package only exists in that shellnix-shell -p <package># Nix-shell can use a default `shell.nix` file first and set up a base for other nix-shells in addition to packages specified by `-p`
# --pure` flag makes sure that the bash environment from your system is not inherited, useful for CI environments and reproducible builds/executablesnix-shell --pure
# List installed nix packagesnix-env -q# `--pure` can be used inside reproducible scripts in shebangs like:#! /usr/bin/env nix-shell#! nix-shell --pure -i python -p "python38.withPackages (ps: [ ps.django ])"#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/2a601aafdc5605a5133a2ca506a34a3a73377247.tar.gz
import django
print(django)Single-user installations of Nix should run this:
nix-channel --update; nix-env -iA nixpkgs.nix nixpkgs.cacert
Multi-user Nix users on Linux should run this
sudo nix-channel --update; nix-env -iA nixpkgs.nix nixpkgs.cacert; systemctl daemon-reload; systemctl restart nix-daemon
-
Updates
nix-channel --update nixpkgs- update channelsand
nix-env -u '*'- update packages -
Rollbacks
nix-env --rollback- rollback to previous version of packages -
Garbage Collection
nix-collect-garbage -d- remove old versions of packages, should be run periodically since other Nix commands do not delete old items
Security
Section titled “Security”Different user modes are available.
- Single user mode = similar to other package management tools, a single user like root does all package management operations, others can use packages, but not do package management
- Multiple user mode = every user can do package management operations, software installs do not require root privileges
Appendix - Possible packages for Nixos
Section titled “Appendix - Possible packages for Nixos”- VS Code
- drawio
- openrgb
- peazip - not available yet
- emacs - available, but not native compilation?
- fsearch
- microsoft-edge
- vlc
- keepassxc
- firefox-… versions
See Also
Section titled “See Also”- Nix Guides and Information - Nix Guides and Information
- Nix and Poetry for Python App Packaging - Nix and Poetry for Python App Packaging