NixOS

From Leo's Notes
Revision as of 22:44, 23 April 2020 by Leo (talk | contribs) (Created page with "NixOS is a Linux distribution based upon the Nix package manager. The idea is to build a immutable system from a modular and purely functional specification. Software, config...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
This page was last edited on 23 April 2020, at 22:44.

NixOS is a Linux distribution based upon the Nix package manager. The idea is to build a immutable system from a modular and purely functional specification. Software, configuration files, scripts, etc. are generated from a specification. This method of creating a system ensures that everything comes up deterministically and reproducibly. Alterations to configuration files are also defined in this specification, allowing for easy tracability of configuration file changes. Upgrades involve updating the specification file and then rebuilding the system which in essence allows software to update atomically.

This is in contrast to the conventional way of managing a system: an imperative way where where packages are installed and updated in place and configuration files are created and edited after installation.

Nix

Central to the idea of NixOS is the Nix package manager. Packages (also known as derivations) are stored under /nix/store/hash-name-version, where a cryptographic hash uniquely identifies the derivation. All files under the Nix store are immutable. For example, bash would be in /nix/store/s4zia7hhqkin1di0f187b79sa2srhv6k-bash-4.2-p45/, under its own bin/bash directory. NIX will arrange binaries in your PATH appropriately.

This method of handling software packages allows for multiple versions of the same software package to be installed. Any dependencies are handled by installing the exact version of the dependency and then ensuring the proper link. This means that you could run mysql 5.2 with glibc-2.18, and mysql 5.5 with glibc-2.19 all in the same system.

Package upgrades are handled by installing the newer version on the system and then switching to that newer version.

The Nix database is stored at /nix/var/nix/db

Profile

A profile in Nix gathers separate components spread among different paths into a unified path. They are versioned (known as a generation) that allows for easy roll back.

Profiles are stored under ~/.nix-profile which is a symlink to /nix/var/nix/profiles/default. Different generations of the profile are stored /nix/var/nix/profiles/.