nix package manager
Why?
- Multiple versions support.
- No missing dependencies issue. (at time of packaging)
- Multi-user support with non-sudo install
- Allows easy rollbacks and every updates are atomic (i.e., each update will not affect previous versions)
- Garbage collector (removing unused packages files after uninstall)
- Functional package language (Supports building variants of package independently, nix expression are deterministic : : building a Nix expression twice should yield the same result)
- Install from source or using binaries also.
- Huge plethora of existing packages
- Managing build environments. (sets env vars etc)
- Runs on macOS and Linux
NixOS
It uses Nix not just for package management but also to manage the system configuration. This means, among other things, that it is easy to roll back the entire configuration of the system to an earlier state.
Installation
- Install Nix
bash
bash <(curl -L https://nixos.org/nix/install) --daemon # Multi-user installationNOTE
Multi-user mode has one important limitation: only root and a set of trusted users specified in nix.conf can specify arbitrary binary caches. So while unprivileged users may install packages from arbitrary Nix expressions, they may not get pre-built binaries.
- Configuring Nix
bash
mkdir ~/.config/nix
echo "experimental-features = nix-command flakes" > ~/.config/nix/nix.confSome Commands
Roll Back to old version
bash
nix-env --upgrade --attr nixpkgs.some-package
nix-env --rollbackRemove unused packages
bash
nix-env --uninstall firefox # package isn’t deleted from the system and is available for rollback
nix-collect-garbageInstall from sourplethorace
bash
nix-env --install --attr nixpkgs.firefoxGet all the dependencies of a package
bash
nix-shell '<nixpkgs>' --attr package-nameTesting a package
It runs the package in testing bash environment.
bash
nix-shell --packages helloUpdate packages
bash
nix-channel --update nixpkgs
nix-env --upgrade '*'Rollback the package
bash
nix-env --rollbackDelete old or uninstalled packages
bash
nix-collect-garbage --delete-oldUpgrade Nix on Linux for Multi-user install (in sudo env)
bash
nix-channel --update; nix-env --install --attr nixpkgs.nix nixpkgs.cacert; systemctl daemon-reload; systemctl restart nix-daemonUninstall Nix for Multi-User Linux env
Remove daemon, files, users and group
bashsudo systemctl stop nix-daemon.service sudo systemctl disable nix-daemon.socket nix-daemon.service sudo systemctl daemon-reload sudo rm -rf /etc/nix /etc/profile.d/nix.sh /etc/tmpfiles.d/nix-daemon.conf /nix ~root/.nix-channels ~root/.nix-defexpr ~root/.nix-profile for i in $(seq 1 32); do sudo userdel nixbld$i done sudo groupdel nixbldRemove references
There may also be references to Nix in
- /etc/bash.bashrc
- /etc/bashrc
- /etc/profile
- /etc/zsh/zshrc
- /etc/zshrc
which you may remove.