3 NixOS
Tibo De Peuter edited this page 2023-10-18 21:39:17 +02:00

NixOS

Installation

I used this guide so if you follow along there, it should be straightforward for you too.

Depending on how you're feeling today, you should prepare an installation medium with either the graphical or minimal installer.

Configuring disks

fdisk -l
fdisk /dev/sdx
<.../>

mkfs.fat -F 32 -n NIX-BOOT /dev/sdx1
mkswap -L SWAP /dev/sdx2
mkfs.ext4 -L NIX-ROOT /dev/sdx3

mount /dev/disk/by-label/NIX-ROOT /mnt
mkdir -p /mnt/boot/efi
mount /dev/disk/by-label/NIX-BOOT /mnt/boot/efi
swapon /dev/disk/by-label/SWAP

Using nixos-generate-config

If you do not have an existing configuration repository, or you just want to start from scratch, (automatically) generate a basic config using:

nixos-generate-config --root /mnt

You probably want to tweak this configuration. Remember to:

  • Point boot.efiSysMountPoint to /boot/efi.
  • Enable networking.
  • Add a user. I recommend to set a password using initialPassword.
  • Install git.
  • Map you disk configuration to the labels you just made. This is done in /etc/nixos/hardware-configuration.nix.

Then you can cd /mnt and nixos-install. When the installation is successful, reboot and remove the installation media.

Afterwards, you should change the password of your user. Then you can choose to build your configuration from here or integrate with an existing configuration.

Using existing flake

If you have a repository and you want to 'clone' an existing machine using flakes.

Clone your repository and go inside the folder containing the flake.nix file.

nixos-install --flake .#<hostname>

Alternatively, if you don't want to clone the repository first:

nixos-install --flake https://<url_to_your_repo>#<hostname>

It is possible that you might have to append --experimental-features 'nix-command flakes' if your system does not have those options enabled yet.