For AI agents: the complete documentation index is available at /en/llms.txt, the full documentation bundle is available at /en/llms-full.txt, and this page is available as Markdown at /en/vps/nixos.md.

NixOS

There is no NixOS template in the portal, but you can install NixOS yourself in a few minutes. You order the server with Debian 13 and then run nixos-anywhere from your own computer. The tool replaces Debian with NixOS over SSH, and the server restarts into NixOS with your configuration.

Warning

Everything on the server's disk is deleted. Do this on a new server, or copy anything you want to keep first.

What you need

  • A VPS with Debian 13 and at least 2 GB RAM: VPS Medium, VPS Bygg själv or a server in VPS Cloud. The installation runs in the server's memory, and on VPS Small with 1 GB it stops with Kexec failed. Debian is then left untouched.

  • Debian 13 as the OS template. The Ubuntu templates have Secure Boot turned on, and NixOS does not boot with it.

  • Nix on your computer, running Linux, macOS or WSL2 on Windows. On Debian 13 Nix is available as a package:

    sudo apt install nix-setup-systemd
    sudo usermod -aG nix-users $USER

    Log out and in again afterwards. On other systems, install Nix following nixos.org/download.

Turn on flakes, which the installation uses:

mkdir -p ~/.config/nix
echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf

Step 1: Get the server's network settings

The NixOS server gets static addresses, so you need to know what Debian was given. Log in to the server with the username from the portal, see Getting started, and run:

ip -br link
ip -br addr
ip route
ip -6 route

Write down:

WhatWhereExample
The MAC address of eth0ip -br linkbc:24:11:20:04:7d
The IPv4 address with netmaskip -br addr, the eth0 line193.180.173.29/24
The IPv6 address with netmaskip -br addr, the eth0 line, the address that does not start with fe802a12:5bc5:0:500::29/64
The IPv4 gatewayip route, the default via line193.180.173.1
The IPv6 gatewayip -6 route, the default via line2a12:5bc5:0:500::1

If the server has a private network, also write down the MAC address of eth1.

NixOS names the network cards ens18 and ens19 instead of eth0 and eth1. The configuration below picks the cards by MAC address, so the names do not matter.

Step 2: Write the configuration

Create a directory on your computer, for example nixos-vps, with three files.

flake.nix says which NixOS version you want:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
    disko.url = "github:nix-community/disko";
    disko.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { nixpkgs, disko, ... }: {
    nixosConfigurations.vps = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        disko.nixosModules.disko
        ./configuration.nix
      ];
    };
  };
}

disk-config.nix partitions the disk: an EFI partition and a root partition on the rest.

{
  disko.devices.disk.main = {
    device = "/dev/vda";
    type = "disk";
    content = {
      type = "gpt";
      partitions = {
        ESP = {
          size = "512M";
          type = "EF00";
          content = {
            type = "filesystem";
            format = "vfat";
            mountpoint = "/boot";
            mountOptions = [ "umask=0077" ];
          };
        };
        root = {
          size = "100%";
          content = {
            type = "filesystem";
            format = "ext4";
            mountpoint = "/";
          };
        };
      };
    };
  };
}

configuration.nix is the server itself. Replace the hostname, MAC address, addresses, gateways, username and SSH key with your own:

{ modulesPath, ... }:
{
  imports = [
    (modulesPath + "/profiles/qemu-guest.nix")
    ./disk-config.nix
  ];

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

  # The console in the portal
  boot.kernelParams = [ "console=tty0" "console=ttyS0,115200" ];

  # The root grows when you make the disk bigger
  boot.growPartition = true;
  fileSystems."/".autoResize = true;

  # The guest agent, so that backups are consistent
  services.qemuGuest.enable = true;

  time.timeZone = "Europe/Stockholm";

  networking.hostName = "server1";
  networking.useNetworkd = true;
  networking.useDHCP = false;
  networking.nameservers = [ "94.142.251.250" "2a12:5bc1::250" ];

  systemd.network.networks."10-publik" = {
    matchConfig.MACAddress = "bc:24:11:20:04:7d";
    address = [ "193.180.173.29/24" "2a12:5bc5:0:500::29/64" ];
    routes = [
      { Gateway = "193.180.173.1"; }
      { Gateway = "2a12:5bc5:0:500::1"; }
    ];
  };

  services.openssh = {
    enable = true;
    settings.PasswordAuthentication = false;
    settings.KbdInteractiveAuthentication = false;
    settings.PermitRootLogin = "no";
  };

  users.users.itrhndbk = {
    isNormalUser = true;
    extraGroups = [ "wheel" ];
    openssh.authorizedKeys.keys = [
      "ssh-ed25519 AAAA... du@dator"
    ];
  };
  security.sudo.wheelNeedsPassword = false;

  nix.settings.experimental-features = [ "nix-command" "flakes" ];

  system.stateVersion = "26.05";
}

The firewall is on from the start and only lets SSH in. Open more ports with, for example, networking.firewall.allowedTCPPorts = [ 80 443 ];.

Private network

If the server has a private network, add a block for the second card with the MAC address of eth1 and the private address you have chosen. No gateway:

  systemd.network.networks."20-privat" = {
    matchConfig.MACAddress = "bc:24:11:b7:f9:03";
    address = [ "10.10.0.11/24" ];
  };

Step 3: Install

Lock the versions and start the installation, with the username and address from the portal:

cd nixos-vps
nix flake lock
nix run github:nix-community/nixos-anywhere -- --flake .#vps \
  --target-host itrhndbk@193.180.173.29

nixos-anywhere starts a NixOS installer in the server's memory, partitions the disk, installs and restarts the server. It takes about five minutes. When it says ### Done! ### the server is running NixOS.

flake.lock records exactly which versions were installed. Keep it together with the other files, preferably in git.

Step 4: Log in

The server has new host keys. Remove the old entry and log in:

ssh-keygen -R 193.180.173.29
ssh itrhndbk@193.180.173.29

Set a password on your account, so that you can log in via Console in the portal if the network should act up:

sudo passwd itrhndbk

Change and update the server

The simplest way is to keep the configuration on the server. Copy the directory there once:

scp -r nixos-vps itrhndbk@193.180.173.29:

When you have changed something in the files, build and switch to the new configuration on the server:

sudo nixos-rebuild switch --flake ~/nixos-vps#vps

You get security updates by updating the lock file and rebuilding:

cd ~/nixos-vps
nix flake update
sudo nixos-rebuild switch --flake ~/nixos-vps#vps

NixOS releases a new version in May and November, and each version gets security updates for about seven months. Move to a new version by changing nixos-26.05 in flake.nix and running the commands above. Do not change system.stateVersion; it should stay at the version you installed.

Is the directory in git?

Then Nix only sees files that are added to git. Run git add on new files before you build.

What works differently

The NixOS server does not have cloud-init, which the portal uses to set up the other operating systems. Therefore:

  • SSH keys are changed in configuration.nix, not with Reset SSH Keys in the portal.
  • The console password is the one you set with passwd, not the one shown in the portal.
  • Extra IPv4 addresses are added to the address list in 10-publik, with the netmask /24 and no new gateway.
  • Rebuild in the portal installs the OS template you choose. If you want NixOS again, run step 3 once more.

This works as usual:

  • The console in the portal shows the boot menu and the login prompt.
  • Bigger disk: the root grows by itself at the next restart.
  • Backups and snapshots: the guest agent freezes the file system while they are taken, see Backups and snapshots.