My own NixOS system configuration files.
Edit config.json
file to specify device and user.
We will be cooking impermanent BTRFS NixOS setup here. The core idea is to make
four subvolumes on the disk itself - root
for /
, and nix
, persistent
and snapshots
for /nix
, /persistent
and /snapshots
accordingly. Later on
we will be mounting those subvolumes to the folders inside of the root
subvolume
using our nixos mounts config.
Value of the root
subvolume will be overwritten each reboot, while all the other
subvolumes, being outside of root
, will keep their state. In particular, we're
really interested in persistent
, which will keep our documents and other important
data saved on the disk between reboots, and snapshots
which will be used to store
root
subvolume snapshots to keep track of previously written files. This is needed
to being able to restore some sensitive data if it was forgotten to be persisted.
Lookup main storage drive name with the lsblk
. Then:
sudo -i
parted /dev/sda -- mklabel gpt
parted /dev/sda -- mkpart ESP fat32 1MB 512MB
parted /dev/sda -- set 1 esp on
parted /dev/sda -- mkpart primary 512MB -16GB
parted /dev/sda -- mkpart swap linux-swap -16GB 100%
Verify partitions names via said lsblk
again. Then:
mkfs.fat -F 32 -n boot /dev/sda1
mkfs.btrfs -L nixos /dev/sda2
mkswap -L swap /dev/sda3
mount /dev/sda2 /mnt
swapon /dev/sda3
btrfs subvolume create /mnt/root
btrfs subvolume create /mnt/nix
btrfs subvolume create /mnt/persistent
btrfs subvolume create /mnt/snapshots
Later on we will be mounting other btrfs subvolumes to these folders, and root subvolume to the /
.
mkdir /mnt/root/boot
mkdir /mnt/root/nix
mkdir /mnt/root/persistent
mkdir /mnt/root/snapshots
This empty snapshot will be used to restore the clean system state for impermanence setup.
mkdir /mnt/snapshots/root
btrfs subvolume snapshot -r /mnt/root /mnt/snapshots/root/blank
umount /mnt
mount -o subvol=root /dev/sda2 /mnt
mount -o subvol=nix /dev/sda2 /mnt/nix
mount -o subvol=persistent /dev/sda2 /mnt/persistent
mount -o subvol=snapshots /dev/sda2 /mnt/snapshots
mount /dev/sda1 /mnt/boot
nixos-generate-config --root /mnt
Verify /mnt/etc/nix/hardware-configuration.nix
file using nano
. It must contain mount options
for /nix
, /persistent
, /snapshots
and /
being a btrfs subvolumes (options field), /boot
being
a mount of /dev/sda1
, and a swap device /dev/sda3
.
Then go to /mnt/etc/nix/configuration.nix
and:
- Set
networking.hostName
to a proper value. - Set
networking.networkmanager.enable = true;
. - In
environment.systemPackages
enablegit
,curl
,wget
,vim
andmicro
(more is better right?). - Add flakes support with this:
nix.settings.experimental-features = [ "nix-command" "flakes" ];
. - Allow unfree packages with this:
nixpkgs.config.allowUnfree = true;
.
nixos-install
reboot
Create root.password
and <your username>.password
files in the /persistent
folder
containing your accounts' encrypted passwords.
mkpasswd -m sha-512
Clone this repo and edit the flakeConfig.json
file to setup your user.
sudo git clone https://github.com/krypt0nn/dotfiles /system-flake
sudo nix flake update /system-flake
sudo nixos-rebuild boot --flake /system-flake
restart
Done. Welcome to your impermanent NixOS system!
Boot from the live iso used to install the system. Then:
sudo -i
mount -o subvol=root /dev/sda2 /mnt
mount -o subvol=nix /dev/sda2 /mnt/nix
mount -o subvol=persistent /dev/sda2 /mnt/persistent
nixos-enter
Also you've probably forgot to create accounts' password files. Check out stage 10.