Skip to content

NixOS and Nix functional package manager

  • 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
  • Roll back easy with generations

  • Good for reproducibility, stability, frequent system changes

  • Requires command line and configuration files

How to use NixOS package manager

Examples

  • Install using Nix shell script
  • 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 /etc files
  • PATH should include nix binaries
  • During install, Nix installer will use proxy environment variables
Terminal window
# List all packages available in installed channels (repositories)
nix-env -qaP
# Install package
nix-env -iA nixpkgs.<package>
# Test packages with `which <package>`
# uninstall package
nix-env -e <package>
# Build an download dependencies in your Nix store and start bash shell with required environment variables
nix-shell
# Install package and go into shell with it, package only exists in that shell
nix-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/executables
nix-shell --pure
# List installed nix packages
nix-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)

Upgrade Nix:

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

  1. Updates

    nix-channel --update nixpkgs - update channels

    and

    nix-env -u '*' - update packages

  2. Rollbacks

    nix-env --rollback - rollback to previous version of packages

  3. Garbage Collection

    nix-collect-garbage -d - remove old versions of packages, should be run periodically since other Nix commands do not delete old items

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
  • VS Code
  • drawio
  • openrgb
  • peazip - not available yet
  • emacs - available, but not native compilation?
  • fsearch
  • microsoft-edge
  • vlc
  • keepassxc
  • firefox-… versions