NixOS Install
Setup fresh NixOS install on an internal or test server.
This guide is basically the same as the official NixOS Install docs with small adjustments or notes.
Server requirements
To register a new server, place a request with these details:
- Type:
VM - OS:
NixOS -> Minimal ISO https://nixos.org/download/ - VM: min 2 CPU; 4GB RAM; 64GB SSD
- 24x7 high reliability/ monitoring
- placement: one of the internal DC zones in the internal network (not DMZ!)
- backup: yes, daily
Workflow
Since we cannot register everything at once, the workflow for server setup is currently roughly as follows:
- Server registration (one at a time)
- this provides you with a server number
- Firewall for outbound HTTPS
- rules from FQDN
s....swr.ardto HTTPS 443
- rules from FQDN
- NixOS install
- afterwards this server no longer announces itself as
nixos
- afterwards this server no longer announces itself as
- repeat server registration steps
- Firewall for NATS with all servers — copy-paste values in Firewall
Step-by-step
Log into the server via SSH. ssh s000... might not work since the new NixOS install announces itself as hostname nixos.
For this to work your SSH key also needs to be placed in /home/nixos/.ssh/authorized_keys or /root/.ssh/authorized_keys.
ssh root@nixos
Identify the target disk (e.g. sda).
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS
Confirm the installer booted in UEFI mode.
test -d /sys/firmware/efi && echo UEFI || echo BIOS
Partition and format the virtual disk.
parted /dev/sda -- mklabel gpt
parted /dev/sda -- mkpart root ext4 512MB -8GB
parted /dev/sda -- mkpart swap linux-swap -8GB 100%
parted /dev/sda -- mkpart ESP fat32 1MB 512MB
parted /dev/sda -- set 3 esp on
mkfs.ext4 -L nixos /dev/sda1
mkswap -L swap /dev/sda2
mkfs.fat -F 32 -n boot /dev/sda3
Mount partition.
mount /dev/disk/by-label/nixos /mnt
mkdir -p /mnt/boot
mount -o umask=077 /dev/disk/by-label/boot /mnt/boot
Generate the NixOS config.
nixos-generate-config --root /mnt
Check IP config to set static IP.
ip -br addr; ip route; nmcli -t -f NAME,DEVICE,TYPE con show'
The first block in the second line print something like ens33 or eth0. This is the network interface name. The line also shows the IP address of the interface (e.g. 10.xxx.xxx.xxx/24).
Somewhere it says default via, which is the default gateway.
Update the config: insert hostName, SSH keys and update networking config from previous step.
nano /mnt/etc/nixos/configuration.nix
# ...
networking.hostName = "s000...";
users.users.root.openssh.authorizedKeys.keys = [
# ...
];
nix.settings.experimental-features = [ "nix-command" "flakes" ];
programs.zsh.enable = true;
services.openssh = {
enable = true;
settings.PermitRootLogin = "yes";
settings.PasswordAuthentication = false;
};
networking.nameservers = [
"10.127.201.221"
"10.63.101.221"
"10.191.201.221"
];
networking.networkmanager.unmanaged = [ "ens33" ];
networking.interfaces.ens33.ipv4.addresses = [
{
address = "10.xxx.xxx.xxx";
prefixLength = 24;
}
];
networking.defaultGateway = {
address = "10.xxx.xxx.1";
interface = "ens33";
};
Run installation.
nixos-install
reboot
Post Install
Download the remote config with the init command (copies the whole folder)
just nix-download-init eventhub-connect-xxx
Merge the downloaded hardware-configuration.nix into the correct host folder. update config.nix if needed (static IP addresses).
Then upload the config to the server.
just nix-upload eventhub-connect-xxx
SSH into the server with the new hostname.
ssh s000...
cd /etc/nixos
nixos-rebuild switch --flake /etc/nixos#eventhub-connect-xxx
Known Problems
Could not resolve hostname (6) Could not resolve host: cache.nixos.org;–> Fix resolv.conf- otherwise:
ip route replace default via 10.xxx.xxx.1 dev ens33 src 10.xxx.xxx.xxx
- otherwise:
- ssh
Permission denied–> Fixauthorized_keys