NixOS

Taking the ideas of the Nix package manager and applying them to the whole operating system.

The whole system is defined in a configuration file, usually placed in /etc/nixos/configuration.nix.

This is a minimal configuration.nix example:

{ config, pkgs, ... }:

{
  imports =  [ ./hardware-configuration.nix ];

  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  services.xserver.enable = true;
  services.xserver.displayManager.gdm.enable = true;
  services.xserver.desktopManager.gnome.enable = true;

  users.users.alice = {
    isNormalUser = true;
    extraGroups = [ "wheel" ];
    packages = with pkgs; [
      firefox
      vlc
    ];
  };

  system.stateVersion = "23.11";
}

With hardware-configuration.nix being specific to a computer and usually autogenerated by nixos-generate-config:

{ config, lib, pkgs, modulesPath, ... }:

{
  boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "usbhid" "usb_storage" "sd_mod" "sdhci_pci" ];
  boot.kernelModules = [ "kvm-amd" ];

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/6132cd3c-aba6-4f51-9360-a064e98f6942";
      fsType = "ext4";
    };

  boot.initrd.luks.devices."luks-fde45edd-d98c-4e9e-aa8a-541266584cc0".device = "/dev/disk/by-uuid/fde45edd-d98c-4e9e-aa8a-541266584cc0";

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/FADD-B2BE";
      fsType = "vfat";
    };

  networking.useDHCP = lib.mkDefault true;
  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
  hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

Options

All available options are searchable on https://search.nixos.org/options, they are implemented in the nixpkgs repository (https://github.com/NixOS/nixpkgs/tree/master/nixos).

Rebuilding

Build the system and switch to the new configuration:

sudo nixos-rebuild switch

no manual sudo, all changes saved in git