NixOS: Difference between revisions
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..." |
mNo edit summary |
||
| Line 16: | Line 16: | ||
Profiles are stored under {{code|~/.nix-profile}} which is a symlink to {{code|/nix/var/nix/profiles/default}}. Different generations of the profile are stored {{code|/nix/var/nix/profiles/}}. | Profiles are stored under {{code|~/.nix-profile}} which is a symlink to {{code|/nix/var/nix/profiles/default}}. Different generations of the profile are stored {{code|/nix/var/nix/profiles/}}. | ||
nix-env handles the profiles and all the symlinks in this location. paths are also merged by nix-env. | |||
== Introduction == | |||
Various commands that were introduced in Chapter 3 of the Nix Pills. | |||
{| class="wikitable | |||
! width="40%" | Command | |||
! Description | |||
|- | |||
| {{code|nix-env}} | |||
| Manages environments, profiles, and their generations | |||
|- | |||
| {{code|nix-env -i hello}} | |||
| installs the hello environment | |||
|- | |||
| {{code|nix-env --list-generations}} | |||
| lists all environment generations | |||
|- | |||
| {{code|nix-env -q}} | |||
| lists all derivations | |||
|- | |||
| {{code|nix-env -q --references `which hello`}} | |||
| shows all derivations that are required by the given binary | |||
|- | |||
| {{code|nix-env -q --referrers `which hello`}} | |||
| shows all derivations that are dependent on the given binary | |||
|- | |||
| {{code|nix-env --rollback}} | |||
| rolls back the generation by one | |||
|- | |||
| {{code|nix-env -G 3}} | |||
| sets the environment generation to the given generation (3) | |||
|- | |||
| {{code|nix-env -u}} | |||
| upgrades all packages in the environment | |||
|- | |||
| {{code|nix-env -e '*'}} | |||
| Uninstalls everything from the current environment. You can recover this by running nix-env from the nix store and reinstalling the nix-env derivative or roll back the environment generation. | |||
|} | |||
Closures of a derivation is a recursive list of all dependencies that are required. | |||
{{code|nix-store -qR `which man`}} or {{code|nix-store -q --tree `which man`}} | |||
Channels are basically like repos. | |||
{| class="wikitable | |||
! width="40%" | Command | |||
! Description | |||
|- | |||
| {{code|nix-channel --list}} | |||
| lists all channels. This is configured in ~/.nix-channels | |||
|- | |||
| {{code|nix-channel --update}} | |||
| Synchronizes the channel repo data | |||
|} | |||
Revision as of 22:02, 26 April 2020
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/.
nix-env handles the profiles and all the symlinks in this location. paths are also merged by nix-env.
Introduction
Various commands that were introduced in Chapter 3 of the Nix Pills.
| Command | Description |
|---|---|
nix-env
|
Manages environments, profiles, and their generations |
nix-env -i hello
|
installs the hello environment |
nix-env --list-generations
|
lists all environment generations |
nix-env -q
|
lists all derivations |
nix-env -q --references `which hello`
|
shows all derivations that are required by the given binary |
nix-env -q --referrers `which hello`
|
shows all derivations that are dependent on the given binary |
nix-env --rollback
|
rolls back the generation by one |
nix-env -G 3
|
sets the environment generation to the given generation (3) |
nix-env -u
|
upgrades all packages in the environment |
nix-env -e '*'
|
Uninstalls everything from the current environment. You can recover this by running nix-env from the nix store and reinstalling the nix-env derivative or roll back the environment generation. |
Closures of a derivation is a recursive list of all dependencies that are required.
nix-store -qR `which man` or nix-store -q --tree `which man`
Channels are basically like repos.
| Command | Description |
|---|---|
nix-channel --list
|
lists all channels. This is configured in ~/.nix-channels |
nix-channel --update
|
Synchronizes the channel repo data |