Overview of the NixOS Linux distribution: Difference between revisions

From NixOS Wiki
imported>Ixxie
imported>Ixxie
Line 71: Line 71:
In addition to declarative system configuration, NixOS offers imperative commands to manage ''user specific'' package management. These operations are managed by the <code>nix-env</code> command line tool. The following is a summary of some common operations that can be performed with it:
In addition to declarative system configuration, NixOS offers imperative commands to manage ''user specific'' package management. These operations are managed by the <code>nix-env</code> command line tool. The following is a summary of some common operations that can be performed with it:


'''Common <code>nix-env</code> Commands:'''
{|  class="wikitable"
{|  class="wikitable"
|+ Basic <code>nix-env</code> Commands
|Searching for packages
|Searching for packages
|<code>nix-env -qaP '.*packagename.*'</code>
|<code>nix-env -qaP '.*packagename.*'</code>
Line 93: Line 93:
Nix ''channels'' are mechanisms for distributing Nix expressions alongside the associated binaries for them. Nix channels are automatically updated once a certain tests are passed in Nixpkgs' Hydra instance.
Nix ''channels'' are mechanisms for distributing Nix expressions alongside the associated binaries for them. Nix channels are automatically updated once a certain tests are passed in Nixpkgs' Hydra instance.


'''Channel Types:'''
{|  class="wikitable"
{|  class="wikitable"
|+ Channel Types
|Stable
|Stable Channels
|''nixos-17.03''
|''nixos-17.03''
|These receive conservative updates for fixing bugs and security vulnerabilities.
|These receive conservative updates for fixing bugs and security vulnerabilities.
|-
|-
|The Unstable Channel
|Unstable
|''nixos-unstable''
|''nixos-unstable''
| Corresponds to the main development branch of Nixpkgs, delivering the latest tested updates.
| Corresponds to the main development branch of Nixpkgs, delivering the latest tested updates.
|-
|-
|Small Channels
|Small
|''nixos-17.03-small'' or ''nixos-unstable-small''
|''nixos-17.03-small'' or ''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.
| Identical to their normal namesakes, but containing fewer binaries. This means they update faster but require more to be built from source.

Revision as of 11:43, 3 September 2017

Warning: "This discussion article is incomplete, so contributions are welcome. Please consult the discussion article metapage for guidelines on contributing to discussion articles."

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. Alongside this declarative operation mode, NixOS supports imperative package and user management. In NixOS, all components of the distribution - including the kernel, system packages and configuration files - are built by Nix from purely functional Nix Expressions. Since Nix supports binary caching, this provides a convenient compromise between source-based and binary approaches, allowing the use of a binaries for standard components and custom built packages and modules when needed. Stable NixOS releases are delivered biannually, with the latest stable version being 17.03. 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

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. Nix channels are automatically updated once a certain tests are passed in Nixpkgs' Hydra instance.

Channel Types:

Stable nixos-17.03 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.03-small or 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.

Internals

Nix Store

Profiles

Development

GitHub

Hydra

History

See also