Packages
The packages terms section below tries to define the various terms with greater precision. For this part, I'll try to just give a reasonably correct overview and trade on precision of terms where it improves clarity.
Nix is a package manager, but it does things a little differently than most. With nix, each package receives a unique hash, which is calculated from all of the package's dependencies (sources, patches, its own dependencies and so on).
As each package is placed into its own path in the nix store (/nix/store
),
it becomes possible to have many copies of Node installed, themselves
possibly depending on different versions of underlying libraries, without
conflict.
Each package installed into the store has a path of the type:
/nix/store/<hash>-<package-name>
, e.g.
/nix/store/dnhhyhfql3cs9jmrhd3a05620higxy0i-nodejs-18.14.2
- note that
nodejs-18.14.2
is the package name.
With flakes, you can then assemble entire environments (development shells), which if used, creates a shell environment into which several packages installed through nix are made available.
This approach has many benefits, from multiple, isolated environments (not unlike Docker containers), to saving space (a given package is installed once, not once per environment). Furthermore, as each package is built in an isolated environment where only the (transitive-) dependencies of the package are made available, we avoid any hidden/unspecified dependencies from the global environment.
Note
there is no such thing as a build-script per se, see the terminology section below.
Building Packages
Running a package
Some packages have a principal binary, typically of the same name, such as the
vim
binary for the vim
package. In these cases, you can instruct Nix
to launch the specified program like so:
nix run github:NixOS/nixpkgs/nixos-22.11#vim
Building a package
Similar to running a package, you can build and "install" a package:
nix run github:NixOS/nixpkgs/nixos-22.11#vim
After the package is built, you can find a ./result
symlink pointing to the
store entry.
Terminology
Warning
On terminology Don't choke up on all this - however galaxy-brain sounding it seems, we're just shoving bits into packages or places on disk - relax, nothing new here!
The nix community likes words - you'll either find this off-putting and slightly draining, or it'll stoke your inner elistist. Either way, it's mostly of little consequence in daily use, but let's try to go over the concepts, shall we?
Package?
O.M.G - there is no such thing, go away, pleb.
..OK, we kind of have packages. You can talk about the vim, emacs
or firefox packages. But there are no equivalents to a deb
or rpm
package.
Build-script?
Scripts like cowsay define how to build a given package. You could call it a build script, but there is no official term for it. Technically, scripts like these tend to be a function which, when called, will produce a derivation (see below).
Derivation?
Derivations are produced in Nix (the language) by the derivation
function
(or any of the higher-level helpers like mkDerivation
or buildPythonPackage
).
A derivation is saved as a .drv
file to the nix store. It is ultimately this
.drv
file, which Nix uses to build and install the software or resources
(fonts, icon packs, ...).
NAR (Nix Archive!)
This is the equivalent of a .deb
or .rpm
file (the compiled variant,
not the source variant!). A NAR is an archive containing various files -
some of these are likely compiled to fit your specific
system.
Nix Store
A directory on your machine, typically /nix/store
, which contains all
installed packages.
Store Path
A path within the nix store, e.g.
/nix/store/dnhhyhfql3cs9jmrhd3a05620higxy0i-nodejs-18.14.2/
. Note that
each store path follows the form /nix/store/<hash>-<package name>
. Note
that package name, by convention, is both the name of the software package
and its version, e.g. nodejs-18.42.2
.