diff options
| author | Isabella Bastaja <isabella@sorre.xyz> | 2026-10-04 21:29:47 +0200 |
|---|---|---|
| committer | Isabella Bastaja <isabella@sorre.xyz> | 2026-10-06 23:25:49 +0200 |
| commit | 91629938bb4f455c5c04331d4a8fa60253ffa435 (patch) | |
| tree | 99d3c012d31d3fb5bfe2c27bdf430921c53ab0ba /hosts | |
| parent | cdb8341737e398743a5e5b13d24b408fd8398974 (diff) | |
enode: disk setup, minor fixes
Diffstat (limited to 'hosts')
| -rw-r--r-- | hosts/enode/default.nix | 32 | ||||
| -rw-r--r-- | hosts/enode/disko.nix | 108 | ||||
| -rw-r--r-- | hosts/enode/impermenance.nix | 36 |
3 files changed, 157 insertions, 19 deletions
diff --git a/hosts/enode/default.nix b/hosts/enode/default.nix index c2ba04e..c45d7f0 100644 --- a/hosts/enode/default.nix +++ b/hosts/enode/default.nix @@ -1,9 +1,31 @@ -{ pkgs, ... }: { +{ + pkgs, + inputs, + ... +}: +{ imports = [ + inputs.impermanence.nixosModules.impermanence + inputs.disko.nixosModules.disko ./headscale.nix ./caddy.nix + ./disko.nix ]; + boot.initrd.luks.devices = { + cryptroot = { + device = "/dev/disk/by-partlabel/luks"; + allowDiscards = true; + preLVM = true; + }; + }; + + services.btrfs.autoScrub = { + enable = true; + interval = "weekly"; + fileSystems = [ "/" ]; + }; + networking = { networkmanager.enable = true; useDHCP = false; @@ -23,6 +45,11 @@ ]; }; }; + time.timeZone = "Europe/Berlin"; + + security.sudo.extraConfig = '' + Defaults lecture = never + ''; boot.loader = { systemd-boot.enable = true; @@ -30,7 +57,7 @@ }; users = { - users.isabella = { + users.isabella = { isNormalUser = true; description = "Isabella Morgana Bastaja"; extraGroups = [ "wheel" ]; @@ -43,6 +70,7 @@ }; mutableUsers = false; }; + console.keyMap = "us"; services.openssh = { enable = true; diff --git a/hosts/enode/disko.nix b/hosts/enode/disko.nix index 82e7d5f..d9dfb20 100644 --- a/hosts/enode/disko.nix +++ b/hosts/enode/disko.nix @@ -1,32 +1,106 @@ +let + espPartition = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = [ + "default" + ]; + }; + cryptroot = { + type = "luks"; + name = "cryptroot"; + content = { + type = "btrfs"; + extraArgs = [ + "-L" + "nixos" + "-f" + ]; + subvolumes = { + "/root" = { + mountpoint = "/"; + mountOptions = [ + "subvol=root" + "compress=zstd" + "noatime" + ]; + }; + "/root-blank" = { + mountOptions = [ + "subvol=root-blank" + "nodatacow" + "noatime" + ]; + }; + "/home" = { + mountpoint = "/home"; + mountOptions = [ + "subvol=home" + "compress=zstd" + "noatime" + ]; + }; + "/nix" = { + mountpoint = "/nix"; + mountOptions = [ + "subvol=nix" + "compress=zstd" + "noatime" + ]; + }; + "/persist" = { + mountpoint = "/persist"; + mountOptions = [ + "subvol=persist" + "compress=zstd" + "noatime" + ]; + }; + "/lib" = { + mountpoint = "/var/lib"; + mountOptions = [ + "subvol=lib" + "compress=zstd" + "noatime" + ]; + }; + "/log" = { + mountpoint = "/var/log"; + mountOptions = [ + "subvol=log" + "compress=zstd" + "noatime" + ]; + }; + }; + }; + }; +in { disko.devices.disk.vm-disk = { - device = "/dev/vda"; type = "disk"; + device = "/dev/vda"; content = { type = "gpt"; partitions = { ESP = { - type = "EF00"; + label = "boot"; + name = "ESP"; size = "1G"; - content = { - type = "filesystem"; - format = "vfat"; - mountpoint = "/boot"; - mountOptions = [ - "umask=0077" - "nofail" - ]; - }; + type = "EF00"; + content = espPartition; }; - root = { + luks = { size = "100%"; - content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/"; - }; + label = "luks"; + content = cryptroot; }; }; }; }; + + fileSystems."/var/log".neededForBoot = true; + fileSystems."/var/lib".neededForBoot = true; + fileSystems."/persist".neededForBoot = true; } diff --git a/hosts/enode/impermenance.nix b/hosts/enode/impermenance.nix new file mode 100644 index 0000000..9915bb1 --- /dev/null +++ b/hosts/enode/impermenance.nix @@ -0,0 +1,36 @@ +{ lib, ... }: { + boot.initrd.postDeviceCommands = lib.mkAfter '' + echo "Rollback running" > /mnt/rollback.log + mkdir -p /mnt + mount -t btrfs /dev/mapper/cryptroot /mnt + + # Recursively delete all nested subvolumes inside /mnt/root + btrfs subvolume list -o /mnt/root | cut -f9 -d' ' | while read subvolume; do + echo "Deleting /$subvolume subvolume..." >> /mnt/rollback.log + btrfs subvolume delete "/mnt/$subvolume" + done + + echo "Deleting /root subvolume..." >> /mnt/rollback.log + btrfs subvolume delete /mnt/root + + echo "Restoring blank /root subvolume..." >> /mnt/rollback.log + btrfs subvolume snapshot /mnt/root-blank /mnt/root + + umount /mnt + ''; + + # Use /persist as the persistence root, matching Disko's mountpoint + environment.persistence."/persist" = { + hideMounts = true; + directories = [ + "/var/lib/backups" + "/var/lib/headscale" + "/var/lib/caddy" # for certs + ]; + files = [ + "/etc/machine-id" + "/etc/shadow" + "/etc/passwd" + ]; + }; +} |
