Skip to main content

Install

We follow the UEFI part of the official Installation Guide:
NixOS Installation Guide.

Partitioning

Partition the storage using sudo fdisk /dev/sdb. In the interactive prompt partition the storage those settings:

  • g (gpt disk label)
  • n
  • 1 (partition number [1/128])
  • 2048 first sector
  • +500M last sector (boot sector size)
  • t
  • 1 (EFI System)
  • n
  • 2
  • default (fill up partition)
  • default (fill up partition)
  • w (write)

Delete all Files on partitions with:

dd if=/dev/zero of=/dev/sdb1 bs=4096 status=progress
dd if=/dev/zero of=/dev/sdb2 bs=4096 status=progress

Label partitions

Label the partitions using those commands:

sudo mkfs.fat -F 32 /dev/sda1
sudo fatlabel /dev/sda1 NIXBOOT
sudo mkfs.ext4 /dev/sda2 -L NIXROOT

Mount partitions

Mount your boot and root drives so we can access them and install NixOS:

sudo mount /dev/disk/by-label/NIXROOT /mnt sudo mkdir -p /mnt/boot sudo mount /dev/disk/by-label/NIXBOOT /mnt/boot

Create swap file

sudo dd if=/dev/zero of=/mnt/.swapfile bs=1024 count=2097152 # 2GB size sudo chmod 600 /mnt/.swapfile sudo mkswap /mnt/.swapfile sudo swapon /mnt/.swapfile

Create NixOS config

Generate the config using sudo nixos-generate-config --root /mnt

Then, edit the config using sudo -e /mnt/etc/nixos/configuration.nix.

Here are some of the most essential changes to make:

... keep the existing config

Keyboard layout

services.xserver.xkb.layout = "us";

Add a user!

users.users.alice = { isNormalUser = true; description = "Alice"; extraGroups = [ "wheel" ]; # Sudo access shell = pkgs.bash; home = "/home/alice"; };

Networking config (ie: wifi)

Configure bootloader device

boot.loader.grub.device = "/dev/sda"; # or "nodev" for EFI only

Install an editor to edit the configuration

environment.systemPackages = with pkgs; [ nano ]; # or vim!

...

To edit the hardware config, use sudo -e /mnt/etc/nixos/hardware-configuration.nix.

You can then update the file systems to use labels.

...

fileSystems."/" = { device = "/dev/disk/by-label/NIXROOT"; # ... };

fileSystems."/boot" = { device = "/dev/disk/by-label/NIXBOOT"; # ... };

...

Install NixOS

cd /mnt sudo nixos-install

after installation: Run passwd to change user password.

If internet broke/breaks, set wpa_supplicant config flags to connect to wifi.

Then, try one of the following to rebuild without downloads

nixos-rebuild switch --option substitute false
nixos-rebuild switch --option binary-caches ""

install git

rebild with experimental features nix-command and flake

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

networking.hostName = "eliasDesktop";

copy repo to /etc/nixos and rebuild

dont forget to add the correct hardware-configuration...