Jump to content

NixOS: Difference between revisions

From David's Wiki
 
Line 42: Line 42:
</syntaxhighlight>
</syntaxhighlight>


Example config:
<pre>
{ config, pkgs, ... }:
{
  imports = [ ./hardware-configuration.nix ];
  # Bootloader settings
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;


Make sure to add the swap config:
  # 1. ZFS Support for additional drives
<pre>
  boot.supportedFilesystems = [ "zfs" ];
swapDevices = [ {
  networking.hostId = "8425e349"; # Required for ZFS; use 8 random hex digits
  device = "/swapfile";
 
  size = 4096; # In MB
  # 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
}
</pre>
</pre>



Latest revision as of 03:40, 24 December 2025

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