Nix¶
- Building Nix packages
nix-buildinvolves two steps:- evaluation/instantiation (
nix-instantiate): goes from nix expression (.nix) to a derivation (.drv) - realization (
nix-store --realize): goes from a derivation to a store path
- evaluation/instantiation (
- build-loop is how Nix builds software
flowchart LR A[Substitutors] --> B{remainingOutput?} B --No--> C[BuildInputs] C --> D[Build] D --> E[RegisterOutputPaths] B --Yes--> Stop - Nix package is unique across: source, dependencies, build steps, architecture, platform
- Nix can determine the derivation and the final output path ahead of time (needed for caching)
- derivation is platform-specific way to build a package
- output of derivation depends only on the inputs and the build script, and each package has a unique hash
- NixOS boot process:
- Bootloader loads kernel and
initrd initrdmounts partitionsinitrdruns/run/current-system/activate- if first time, it populates POSIX directories (
/bin,/etc,/run,/usr,/var)
- Bootloader loads kernel and
- Nix binary cache
- NAR file is a serialized file format for packages used by the Nix package manager (v/s tar files) because they don't contain any non-deterministic information
.narinfofiles contain metadata info about each package, such as dependencies
- Use of
mkIfwithin module system requires all options to be valid
Useful commands¶
- Find all GC roots
- Roots of a dependency
- Find package versions and their commits
- Find references, referrer, closures
Flakes¶
- Allow unfree
- Make
nixpkgsrefer to the same one in your flake enablednixos