Find a file
snowflake 4ce2cb1572 flake.lock: Update
Flake lock file updates:

• Updated input 'home-manager':
    'github:nix-community/home-manager/6761b8188b860f374b457eddfdb05c82eef9752f' (2023-12-10)
  → 'github:nix-community/home-manager/1488651d02c1a7a15e284210f0d380a62d8d8cef' (2023-12-17)
• Updated input 'home-manager-unstable':
    'github:nix-community/home-manager/d9297efd3a1c3ebb9027dc68f9da0ac002ae94db' (2023-12-12)
  → 'github:nix-community/home-manager/efc177c15f2a8bb063aeb250fe3c7c21e1de265e' (2023-12-19)
• Updated input 'impermanence':
    'github:nix-community/impermanence/0f317c2e9e56550ce12323eb39302d251618f5b5' (2023-10-14)
  → 'github:nix-community/impermanence/123e94200f63952639492796b8878e588a4a2851' (2023-12-19)
• Updated input 'nix-index-database':
    'github:nix-community/nix-index-database/45d82e0a8b9dd6c5dd9da835ac0c072239af7785' (2023-12-11)
  → 'github:nix-community/nix-index-database/4605ccd764fac78b9e4b5b058698cb9f04430b91' (2023-12-18)
• Updated input 'nixos-hardware':
    'github:NixOS/nixos-hardware/fef05bf9c8e818f4ca1425ef4c18e6680becd072' (2023-12-11)
  → 'github:NixOS/nixos-hardware/7763c6fd1f299cb9361ff2abf755ed9619ef01d6' (2023-12-13)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/781e2a9797ecf0f146e81425c822dca69fe4a348' (2023-12-10)
  → 'github:NixOS/nixpkgs/d02ffbbe834b5599fc5f134e644e49397eb07188' (2023-12-18)
• Updated input 'nixpkgs-unstable':
    'github:NixOS/nixpkgs/a9bf124c46ef298113270b1f84a164865987a91c' (2023-12-11)
  → 'github:NixOS/nixpkgs/91a00709aebb3602f172a0bf47ba1ef013e34835' (2023-12-17)
2023-12-20 01:09:19 +00:00
hosts terraform -> opentofu 2023-12-06 13:12:56 +01:00
modules Revert "23.11: remove workaround for network-online.target" 2023-12-13 20:25:40 +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-20 01:09:19 +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 explain repl 2023-12-13 20:24:08 +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 .
# print the value of a configuration settings
:p nixosConfigurations.omega.config.services.openssh.ports
# print _why_ the value is as it is (source of defaults, overwrites)
:p nixosConfigurations.omega.options.services.openssh.ports
# print value of home-manager setting
:p nixosConfigurations.omega.config.home-manager.users.caspervk.programs.ssh.matchBlocks
# print version of package in nixpkgs
:p inputs.nixpkgs.outputs.legacyPackages.x86_64-linux.openssh.version