NixOS

Revision as of 03:40, 24 December 2025 by David (talk | contribs) (Generate a config and install)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
\( \newcommand{\P}[]{\unicode{xB6}} \newcommand{\AA}[]{\unicode{x212B}} \newcommand{\empty}[]{\emptyset} \newcommand{\O}[]{\emptyset} \newcommand{\Alpha}[]{Α} \newcommand{\Beta}[]{Β} \newcommand{\Epsilon}[]{Ε} \newcommand{\Iota}[]{Ι} \newcommand{\Kappa}[]{Κ} \newcommand{\Rho}[]{Ρ} \newcommand{\Tau}[]{Τ} \newcommand{\Zeta}[]{Ζ} \newcommand{\Mu}[]{\unicode{x039C}} \newcommand{\Chi}[]{Χ} \newcommand{\Eta}[]{\unicode{x0397}} \newcommand{\Nu}[]{\unicode{x039D}} \newcommand{\Omicron}[]{\unicode{x039F}} \DeclareMathOperator{\sgn}{sgn} \def\oiint{\mathop{\vcenter{\mathchoice{\huge\unicode{x222F}\,}{\unicode{x222F}}{\unicode{x222F}}{\unicode{x222F}}}\,}\nolimits} \def\oiiint{\mathop{\vcenter{\mathchoice{\huge\unicode{x2230}\,}{\unicode{x2230}}{\unicode{x2230}}{\unicode{x2230}}}\,}\nolimits} \)

Install

The graphical installer is trivial. However, the minimal ISO doesn't handle partitioning for you.

Partitioning and Formatting

# Create a new GPT partition table
parted /dev/sda -- mklabel gpt

# Create the EFI Boot partition
parted /dev/sda -- mkpart ESP fat32 1MB 512MB
parted /dev/sda -- set 1 esp on

# Create the Root partition (ext4)
parted /dev/sda -- mkpart primary ext4 512MB 100%

# Format partitions
mkfs.fat -F 32 -n boot /dev/sda1
mkfs.ext4 -L nixos /dev/sda2

# Mount the root partition
mount /dev/disk/by-label/nixos /mnt

# Mount the boot partition
mkdir -p /mnt/boot
mount /dev/disk/by-label/boot /mnt/boot

# Create a 4GB swapfile (adjust size as needed)
dd if=/dev/zero of=/mnt/swapfile bs=1M count=4096
chmod 600 /mnt/swapfile
mkswap /mnt/swapfile
swapon /mnt/swapfile

Generate a config and install

nixos-generate-config --root /mnt
# Edit the config to your desire
nano /mnt/etc/nixos/configuration.nix

nixos-install

Example config:

{ config, pkgs, ... }:

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

  # Bootloader settings
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  # 1. ZFS Support for additional drives
  boot.supportedFilesystems = [ "zfs" ];
  networking.hostId = "8425e349"; # Required for ZFS; use 8 random hex digits

  # 2. Static IP Configuration
  # Replace 'eth0' with your actual interface name found via 'ip link'
  networking.useDHCP = false;
  networking.interfaces.eth0.ipv4.addresses = [{
    address = "192.168.1.50";
    prefixLength = 24;
  }];
  networking.defaultGateway = "192.168.1.1";
  networking.nameservers = [ "1.1.1.1" "8.8.8.8" ];

  # 3. Swapfile declaration
  swapDevices = [ {
    device = "/swapfile";
    size = 4096; # In MB
  } ];

  # Standard System Settings
  system.stateVersion = "24.11"; # Check the current version on the ISO
}

Install on VPS

For a VPS, first install Ubuntu or Debian. Then run https://github.com/elitak/nixos-infect.

Resources