Nixos

NixOS is an operating system based on Nix.

System Configuration

The entire system is configured through nix config files, usually /etc/nixos/configuration.nix and /etc/nixos/hardware-configuration.nix (host hardware specific).

Consider using Flakes for system configurations. This allows better reproducability and you could manage a whole fleet of hosts within a single context.

To rebuild a new system after configuration change:

sudo nixos-rebuild switch
 
# As a flake
sudo nix-rebuild switch --flake /etc/nixos

For secret management look at sops-nix.

nixpkgs

nixpkgs contains packages and other nix code you can use. Use this site for finding packages as well as options (for system configuration).

Install

Installation can be done with the GUI installer, or if you already have a configuration:

# Setup disks and mount
mount /dev/disk/by-label/nixos /mnt
mkdir -p /mnt/boot
mount -o umask=077 /dev/disk/by-label/boot /mnt/boot
 
# Generate (hardware) config
nixos-generate-config --root /mnt
 
# Install
nixos-install
 
# Flake based
# nixos-install --flake 'path/to/flake.nix#nixos'
 
# Set passwd
nixos-enter --root /mnt -c 'passwd alice'

Build ISO

Starting config for ISO system:

{ pkgs, modulesPath, lib, ... }: {
  imports = [
    "${modulesPath}/installer/cd-dvd/installation-cd-minimal.nix"
  ];
 
  # use the latest Linux kernel
  boot.kernelPackages = pkgs.linuxPackages_latest;
 
  # Needed for https://github.com/NixOS/nixpkgs/issues/58959
  boot.supportedFilesystems = lib.mkForce [ "btrfs" "reiserfs" "vfat" "f2fs" "xfs" "ntfs" "cifs" ];
}

Then you can generate a ISO with nixos-generators:

nix-shell -p nixos-generators --run "nixos-generate --format iso --configuration ./myimage.nix -o result"
 
# Flake based
nix-shell -p nixos-generators --run "nixos-generate --format iso --flake /path/to/flake#system -o result"