Find a file
snowflake 23cbf87bb5 flake.lock: Update
Flake lock file updates:

• Updated input 'home-manager-unstable':
    'github:nix-community/home-manager/4a8545f5e737a6338814a4676dc8e18c7f43fc57' (2023-12-01)
  → 'github:nix-community/home-manager/ac7216918cd65f3824ba7817dea8f22e61221eaf' (2023-12-04)
• Updated input 'nix-index-database':
    'github:nix-community/nix-index-database/bd3aec0ecb0fdde863a7ed2c6caa220c47e22c07' (2023-11-26)
  → 'github:nix-community/nix-index-database/41afa8d1c061beda68502bcc67f2788f3a77042b' (2023-12-03)
• Updated input 'nixos-hardware':
    'github:NixOS/nixos-hardware/8772491ed75f150f02552c60694e1beff9f46013' (2023-11-29)
  → 'github:NixOS/nixos-hardware/fa194fc484fd7270ab324bb985593f71102e84d1' (2023-12-04)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/50aa30a13c4ab5e7ba282da460a3e3d44e9d0eb3' (2023-11-29)
  → 'github:NixOS/nixpkgs/933d7dc155096e7575d207be6fb7792bc9f34f6d' (2023-12-02)
• Updated input 'nixpkgs-unstable':
    'github:NixOS/nixpkgs/e92039b55bcd58469325ded85d4f58dd5a4eaf58' (2023-11-29)
  → 'github:NixOS/nixpkgs/91050ea1e57e50388fa87a3302ba12d188ef723a' (2023-12-01)
2023-12-06 01:07:20 +00:00
hosts 23.11: home-manager 2023-12-01 20:55:41 +01:00
modules sway: enable sway in nixos config too, not just home-manager 2023-12-01 21:53:08 +01:00
overlays 23.11: no more need for ripgrep overlay 2023-12-01 20:57:14 +01:00
.gitignore Initial commit 2023-06-25 01:28:19 +02:00
Containerfile replace gitlab-ci with dumb Containerfile 2023-11-29 01:48:28 +01:00
flake.lock flake.lock: Update 2023-12-06 01:07:20 +00:00
flake.nix 23.11: home-manager 2023-12-01 20:55:41 +01:00
LICENSE fmt license 2023-07-09 00:15:18 +02:00
README.md stateVersion 2023-12-01 17:33:40 +01:00
todo Base 2023-08-01 15:35:59 +02:00

nixos

Installation

Follow the NixOS manual to obtain and boot the installation medium. Use the graphical ISO image since it ships with useful programs such as nmtui; the installation can still be done through the terminal.

Disk Partitioning

For impermanence, partitioning should be done as outlined in the tmpfs as root blogpost, but with /nix as a LUKS-encrypted file system. The boot partition will not be encrypted, since that is poorly supported by systemd-boot. Persistent files will be saved under /nix/persist.

The following is based on the tmpfs as root blogpost, the NixOS manual's partitioning, formatting and LUKS-Encrypted File Systems sections, ArchWiki's LVM on LUKS, the unofficial NixOS wiki Full Disk Encryption, and this GitHub gist.

We create a 1GiB EFI boot partition (/dev/sda1) and the rest will be our LUKS-encrypted volume:

# Create partition table
parted /dev/sda -- mklabel gpt

# Create /boot partition
parted /dev/sda -- mkpart ESP fat32 1MiB 1024MiB
parted /dev/sda -- set 1 esp on

# Create /nix partition
parted /dev/sda -- mkpart primary 1024MiB 100%

# Create and open LUKS-encrypted container
cryptsetup --type=luks2 luksFormat --label=crypted /dev/sda2
cryptsetup open /dev/sda2 crypted

# Create LVM volume group
pvcreate /dev/mapper/crypted
vgcreate vg /dev/mapper/crypted

# Create root logical volume
lvcreate -l 100%FREE vg -n root

# Format partitions
mkfs.fat -F32 -n BOOT /dev/sda1
mkfs.ext4 -L nix /dev/vg/root

The result should be the following (lsblk -f):

NAME          FSTYPE      FSVER            LABEL
sda
├─sda1        vfat        FAT32            BOOT
└─sda2        crypto_LUKS 2                crypted
  └─crypted   LVM2_member LVM2 001
    └─vg-root ext4        1.0              nix

Installation

Whereas the NixOS manual mounts the newly-created nixos partition to /mnt, we will follow the tmpfs as root blogpost and mount /mnt as tmpfs:

mount -t tmpfs none /mnt
mount --mkdir /dev/disk/by-label/BOOT /mnt/boot
mount --mkdir /dev/disk/by-label/nix /mnt/nix
mkdir -p /mnt/nix/persist/

The remaining installation can be done (more or less) according to the NixOS manual.

cd /mnt/nix
git clone https://git.caspervk.net/caspervk/nixos.git tmp
cd tmp/
nixos-generate-config --root /mnt --show-hardware-config
vim hosts/omega/hardware.nix
git add .  # nix sometimes ignores files outside version control
nixos-install --no-root-passwd --flake .#omega

# Make sure to set a password
mkpasswd > /mnt/nix/persist/passwordfile
chmod 400 /mnt/nix/persist/passwordfile

Hardware Configuration

hosts/*/hardware.nix, while initially generated by nixos-generate-config --show-hardware-config, is manually modified.

Impermanence

To find out which of our darlings will be erased on reboot do tree -x /.

Upgrading

sudo nixos-rebuild switch --flake .

State Version

Nixpkgs uses stateVersion so sparingly that auditing the entire nixpkgs repo is easy enough.

Debugging

nix repl
:lf .
:p nixosConfigurations.omega.config.services.openssh.ports
:p nixosConfigurations.omega.config.home-manager.users.caspervk.programs.ssh.matchBlocks
:p inputs.nixpkgs.outputs.legacyPackages.x86_64-linux.openssh.version