Overview of the NixOS Linux distribution: Difference between revisions
imported>Ixxie m Bumped version to 17.09 |
imported>HLandau No edit summary |
||
Line 2: | Line 2: | ||
[https://nixos.org/ NixOS] is a Linux distribution based on the [[Nix Package Manager]]. It supports reproducible and declarative system-wide configuration management as well as atomic upgrades and rollbacks | [https://nixos.org/ NixOS] is a Linux distribution based on the [[Nix Package Manager]]. It supports reproducible and declarative system-wide configuration management as well as atomic upgrades and rollbacks, although it can additionally support imperative package and user management. In NixOS, all components of the distribution — including the kernel, installed packages and system configuration files — are built by [[Nix Package Manager|Nix]] from purely functional (that is, [[Wikipedia:Pure function|side-effect free]]) [[Nix Expression Language|Nix expressions]]. | ||
Since Nix uses binary caching, this provides a unique compromise between the binary-oriented approach used by distributions such as Debian and the source-oriented approach used by distributions such as Gentoo. Binaries can be used for standard components, and custom-built packages and modules can be used automatically when a prebuilt binary is not available. | |||
Stable NixOS releases are delivered biannually. NixOS was created by Eelco Dolstra and Armijn Hemel, and initially released in 2003. It is community developed and maintained under the stewardship of the [https://nixos.org/nixos/foundation.html NixOS Foundation]. | |||
== Usage == | == Usage == | ||
Line 8: | Line 12: | ||
=== Installation === | === Installation === | ||
For a full installation guide | For a full installation guide, see the [https://nixos.org/nixos/manual/index.html#ch-installation Installation chapter of the NixOS manual]. | ||
Most users will install NixOS via [https://nixos.org/nixos/download.html one of the ISO images.] Both "graphical" and "minimal" ISO variants are available for each supported architecture; the "graphical" images are suitable for users intending to install a desktop environment, and the "minimal" images are suitable for users intending to install NixOS in a server role or desiring a smaller ISO image. | |||
The ISO images are hybrid images which can be burnt to optical media or copied raw to a USB drive and booted as-is. See the installation guide for details. | |||
In addition to the ISO images, the [https://nixos.org/nixos/download.html download page] provides a number of alternative methods for installing NixOS. These include: | |||
* virtual appliances in OVA format (compatible with VirtualBox); | |||
* Amazon EC2 AMIs; | |||
* Microsoft Azure blobs. | |||
Additionally, many existing Linux installations can be converted into NixOS installations using [https://github.com/elitak/nixos-infect nixos-infect] or [https://github.com/jeaye/nixos-in-place nixos-in-place]; this is particularly useful for installing NixOS on hosting providers which do not natively support NixOS. | |||
For information on installing NixOS on various ARM devices, see [[NixOS on ARM]]. | |||
=== Declarative Configuration === | === Declarative Configuration === |
Revision as of 11:11, 25 November 2017
NixOS is a Linux distribution based on the Nix Package Manager. It supports reproducible and declarative system-wide configuration management as well as atomic upgrades and rollbacks, although it can additionally support imperative package and user management. In NixOS, all components of the distribution — including the kernel, installed packages and system configuration files — are built by Nix from purely functional (that is, side-effect free) Nix expressions.
Since Nix uses binary caching, this provides a unique compromise between the binary-oriented approach used by distributions such as Debian and the source-oriented approach used by distributions such as Gentoo. Binaries can be used for standard components, and custom-built packages and modules can be used automatically when a prebuilt binary is not available.
Stable NixOS releases are delivered biannually. NixOS was created by Eelco Dolstra and Armijn Hemel, and initially released in 2003. It is community developed and maintained under the stewardship of the NixOS Foundation.
Usage
Installation
For a full installation guide, see the Installation chapter of the NixOS manual.
Most users will install NixOS via one of the ISO images. Both "graphical" and "minimal" ISO variants are available for each supported architecture; the "graphical" images are suitable for users intending to install a desktop environment, and the "minimal" images are suitable for users intending to install NixOS in a server role or desiring a smaller ISO image.
The ISO images are hybrid images which can be burnt to optical media or copied raw to a USB drive and booted as-is. See the installation guide for details.
In addition to the ISO images, the download page provides a number of alternative methods for installing NixOS. These include:
- virtual appliances in OVA format (compatible with VirtualBox);
- Amazon EC2 AMIs;
- Microsoft Azure blobs.
Additionally, many existing Linux installations can be converted into NixOS installations using nixos-infect or nixos-in-place; this is particularly useful for installing NixOS on hosting providers which do not natively support NixOS.
For information on installing NixOS on various ARM devices, see NixOS on ARM.
Declarative Configuration
One of NixOS's most distinguishing features is the ability to declaratively configure the whole system. This is done by specifying a configuration file which defines which packages are installed on the system, which services to run and various other settings and options. This file is normally called configuration.nix
and is found by default at /etc/nixos
, although another location can be set using the environment variable NIX_PATH
. The system configuration is then built with the command nixos-rebuild
. The following is an example of a configuration.nix
file:
{ config, pkgs, ... }:
{
# Import other configuration modules
# (hardware-configuration.nix is autogenerated upon installation)
# paths in nix expressions are always relative the file which defines them
imports =
[
./hardware-configuration.nix
./my-dev-tools.nix
./my-desktop-env.nix
./etc.nix
];
# Name your host machine
networking.hostName = "mymachine";
# Set your time zone.
time.timeZone = "Europe/Utrecht";
# Enter keyboard layout
services.xserver.layout = "us";
services.xserver.xkbVariant = "altgr-intl";
# Define user accounts
users.users =
{
myuser =
{
home = "/home/myuser";
extraGroups = [ "wheel" "networkmanager" ];
isNormalUser = true;
uid = 1000;
};
};
# Install some packages
environment.systemPackages =
with pkgs;
[
ddate
testdisk
zsh
];
# Enable the OpenSSH daemon
services.openssh.enable = true;
}
For inspiration, a variety of NixOS configuration files made by community members can be found in the Configuration Collection.
Imperative Operations
User Environment Management
In addition to declarative system configuration, NixOS offers imperative commands to manage user specific package management. These operations are managed by the nix-env
command line tool. The following is a summary of some common operations that can be performed with it:
Common nix-env
Commands:
Searching for packages | nix-env -qaP '.*packagename.*'
|
Installing a package | nix-env -i packagename
|
List installed packages | nix-env -q
|
Uninstall packages | nix-env -e packagename
|
Upgrade packages | nix-env -u
|
Channels
Nix channels are mechanisms for distributing Nix expressions alongside the associated binaries for them. Official Nix channels are automatically updated once a certain tests are passed in Nixpkgs' Hydra instance. It is also possible to create one's own Nix channels, but here we focus the official channels. A full list of the available official channels is available at https://nixos.org/channels/, but they can be classified into three main types.
Channel Types:
Stable | nixos-17.09 | These receive conservative updates for fixing bugs and security vulnerabilities. |
Unstable | nixos-unstable | Corresponds to the main development branch of Nixpkgs, delivering the latest tested updates. |
Small | nixos-17.09-small, nixos-unstable-small | Identical to their normal namesakes, but containing fewer binaries. This means they update faster but require more to be built from source. |
NixOS will use the root's channels to update the system wide configuration, and user-specific channels to manage the user environment; this means that you must sudo
commands intended to manage the channel your configuration.nix
should use. The following are common commands to manage channels on NixOS:
Listing current channels | nix-channel --list
|
Adding a primary channel | nix-channel --add https://nixos.org/channels/channel-name nixos
|
Adding other channels | nix-channel --add https://some.channel/url my-alias
|
Remove a channel | nix-channel --remove channel-alias
|
Updating a channel | nix-channel --update channel-alias
|
Updating all channels | nix-channel --update
|
Note that after updating channels, one still has to rebuild with nixos-rebuild switch
, but one can also run nixos-rebuild switch --upgrade
to update channels and rebuild.
Internals
Nix Store
Nix parses Nix expressions written in the Nix Expression Language; these are pure functions taking dependencies as arguments and producing derivation specifying a reproducible build environment for the package. The package is then built the Nix store, receiving a unique address specified by a cryptographic hash of the build's dependency graph followed by the package name and version, for example /nix/store/nawl092prjblbhvv16kxxbk6j9gkgcqm-git-2.14.1
. This allows Nix to simultaneously install different versions of the same package, and even different builds of the same version, for example variants built with different compilers.