back Nix package manager
publication: Novembro 27 2022 11:06
last update: Novembro 27 2022 11:06
Nix is a powerful package manager for Linux and other Unix systems that makes package management reliable and reproducible. It uses Nix language to declare packages and configurations to be built by Nix.
Nix uses a single directory to store packages and all other stuff related to it. Packages in Nix are stored in directories such as
│ └── firefox
│ ├── firefox
│ │ └── ...
│ └── mozilla
│ └── ...
│ └── firefox.desktop
where the hash
jibjl... is a unique identifier for the package which takes
into account package build settings and all its dependencies. Notice the
share which we usually in the root directory
in Linux and BSD systems.
The way Nix manages packages allows you to have multiple versions of the same software installed at the same time without any conflict once each package is packaged with all its dependencies. Obviously, it increases storage, but is also allows one to switch between packages or rollback in case you don't like an upgrade with a simple command.
There are two ways to install Nix, single and multi-user. Nix recommends multi-user installation and lists the pros and cons of this method.
My choice when I did install it on a Debian machine for the first time was the
single-user method because I was the only user on that machine and the
uninstall process is easy as running
rm -rf /nix.
Detailed information about each method can be found on Nix manual.
$ sh <(curl -L https://nixos.org/nix/install) --no-daemon
$ sh <(curl -L https://nixos.org/nix/install) --daemon
search for a package
$ nix-env -qaP firefox
Nix allows you to can use regex
$ nix-env -qaP 'firefox.*'
install a package
$ nix-env -iA nixpkgs.firefox
"uninstall" a package
$ nix-env -e firefox
This only makes the package unavailable to the user. Please read Nix quirks below.
upgrade all packages
$ nix-channel --update
$ nix-env -u
Uninstalling a package in Nix does not delete it from your disk as you could, for example, rollback the system to the previous state. As storage is not always enough as we wish, we need to actually delete those unused packages and Nix knows how to do it without breaking anything.
The Nix utility
nix-collect-garbage deletes all packages that aren’t in use
by any user profile or by a currently running program. You can run the garbage
collector after every uninstall, but you will lose the great rollback
functionality of Nix.
Nix also allows you to test a package in a temporary shell environment with
[adriano@laptop:~]$ nix-shell -p jupyter
All packages downloaded for use in this temporary environment remain on your disk after you finish the use and will only be deleted on the next garbage collection unless you actually install it.
Thanks to @firstname.lastname@example.org, @email@example.com, @firstname.lastname@example.org and @email@example.com for the debate on Mastodon which made me write this post.