I keep my nixcfg repository separate from /etc/nixos
. After making changes, the apply.sh
script copies the config into /etc/nixos
and rebuilds the system.
./apply
To update the system, use:
./apply --update
This will apply the configuration, as well as updating the lock file.
- On laptop, swaylock does not activate after closing the lid and opening again even though
swayidle
is configured to do so viabefore-sleep
. - The NVIDIA open driver does not load correctly which causes CUDA to error with code 999. The workaround for now is to manually call
sudo modprobe nvidia_uvm
before using CUDA which fixes the issue until next boot.
First, create a bootable medium from the minimal NixOS installation image, and boot from it on the target machine. Then follow the installation steps:
-
Clone this repository:
git clone https://github.com/gerwin3/nixcfg.git
-
Partition the disks as needed. This configuration expects the following partitions to exist:
- A
nix
partition mounted on/nix
. - A
persist
partition mounted on/persist
. - A transient partition (like
tmpfs
) on/
.
The recommended setup is to create a LUKS disk, then create a btrfs filesystem on it and configure the
nix
andpersist
partitions as btrfs subvolumes.These are (roughly) the steps needed to partition the disk and create the necessary file systems:
# Partition a primary disk and a 2GB boot partition. parted /dev/nvme0n1 -- mklabel gpt parted /dev/nvme0n1 -- mkpart root 2048MB 100% parted /dev/nvme0n1 -- mkpart ESP fat32 1MB 2048MB parted /dev/nvme0n1 -- set 2 esp on # Format and the boot partition (from NixOS installation guide). mkfs.fat -F 32 -n boot /dev/nvme0n1p2 mkdir -p /mnt/boot # Format LUKS encrypted partition, and create btrfs filesystem inside it. cryptsetup luksFormat /dev/nvme0n1p1 cryptsetup open /dev/nvme0n1p1 root mkfs.btrfs /dev/mapper/root mount /dev/mapper/root /mnt # Create subvolumes for nix and persistence, then mount them. btrfs subvolume create /mnt/nix btrfs subvolume create /mnt/persist # Unmount /mnt here since we only need /mnt/boot, /mnt/nix and /mnt/persist umount /mnt # Mount all disks mount -o umask=077 /dev/disk/by-label/boot /mnt/boot mount -o subvol=nix /dev/mapper/root /mnt/nix mount -o subvol=persist /dev/mapper/root /mnt/persist
- A
Note
Refer to the NixOS installation guide UEFI section for more information.
-
Generate the hardware configuration with
nixos-generate-config
or use one of the pre-defined ones. Either way, make sure to modify the configuration to suit your needs.Edit
flake.nix
undernixConfigurations
and add a new configuration. Import the preffered hardware configuration there.The
tmpfs
file system entry needs to be added manually, for example:fileSystems."/" = { device = "none"; fsType = "tmpfs"; options = [ "defaults" "size=25G" "mode=755" ]; neededForBoot = true; };
In the example above, the
tmpfs
file system is 25GB in size. Make sure this number is lower than the available RAM in the system.This is also the time to add other useful stuff:
kernelPackages = pkgs.linuxPackages_latest; loader.efi.canTouchEfiVariables = true;
Also for persistence it is necessary to add
neededForBoot
attributes to each of the three volumes:nix
,persistence
andtmpfs
:fileSystems."/".neededForBoot = true; fileSystems."/nix".neededForBoot = true; fileSystems."/persist".neededForBoot = true;
Refer to framework-13-Ryzen.nix for a good starting point.
Note
It is advisable to temporarily comment out the private modules such
as wireguard.nix
and re-add them after installation when git credentials
have been set up.
-
Generate your user password:
echo "Enter password for main user:" && \ mkdir secrets && \ mkpasswd -m yescrypt | tr -d '\n' > secrets/password
-
Create configuration directories:
sudo mkdir -p /mnt/persist/etc/nixos && \ sudo cp -r * /mnt/persist/etc/nixos
-
Perform installation:
Put the name of the configuration (chosen in step 3) after the hash.
sudo nixos-install --no-root-passwd --flake /mnt/persist/etc/nixos#system && \ sudo reboot now