Some checks failed
Check / eval-and-lint (push) Failing after 5m56s
The impermanence module asserts that the persistent-storage volume and
every volume it bind-mounts into are available in early boot. Persisted
user dirs land under /home, so both /persist and the @home subvolume
must have neededForBoot = true. disko and nixos-generate-config leave it
at the default (false), so a fresh install with impermanence enabled
aborted with:
All filesystems used for persistent storage must have the option
"neededForBoot" set to true.
Please fix the following filesystems: /persist /home
Declare neededForBoot in the module that imposes the requirement.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
134 lines
4.6 KiB
Nix
134 lines
4.6 KiB
Nix
{ config, lib, pkgs, inputs, ... }:
|
|
|
|
let
|
|
cfg = config.nomarchy.system.impermanence;
|
|
in
|
|
{
|
|
imports = [
|
|
inputs.impermanence.nixosModules.impermanence
|
|
];
|
|
|
|
options.nomarchy.system.impermanence = {
|
|
enable = lib.mkEnableOption "Erase Your Darlings (Impermanence) root wipe on boot";
|
|
|
|
# The disko layout names the main LUKS mapping `crypted` on single-disk
|
|
# installs and `crypted_main` on multi-disk installs (see
|
|
# installer/disko-config.nix: `mainLuksName`). The rollback hook must
|
|
# mount the right device, otherwise initrd fails on every boot and the
|
|
# @ → root-blank snapshot is never restored.
|
|
mainLuksName = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "crypted";
|
|
description = ''
|
|
Name of the /dev/mapper entry holding the BTRFS root. Set to
|
|
"crypted_main" on multi-disk installs to match the disko layout.
|
|
'';
|
|
};
|
|
|
|
user = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "nomarchy";
|
|
description = ''
|
|
Primary user whose home subset (.ssh, .gnupg, keyrings, common
|
|
directories) survives the rootfs wipe. Must match the user
|
|
created via `users.users.<name>` — otherwise the persistence
|
|
block is silently inert and the user's home directory is wiped
|
|
on every boot. The installer writes this for you.
|
|
'';
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
# 1. The Rollback Service: wipes the @ root subvolume back to a blank
|
|
# snapshot before the real root is mounted. Plymouth enables systemd
|
|
# stage-1 initrd distro-wide (themes/engine/plymouth.nix), and systemd
|
|
# stage 1 rejects boot.initrd.postDeviceCommands — so this runs as a
|
|
# systemd initrd unit ordered after the LUKS mapping opens and before
|
|
# sysroot is mounted. initrdBin pulls in the binaries the script calls
|
|
# (the systemd initrd doesn't ship coreutils/findutils/btrfs by default).
|
|
boot.initrd.systemd.initrdBin = [
|
|
pkgs.btrfs-progs
|
|
pkgs.coreutils
|
|
pkgs.util-linux
|
|
pkgs.findutils
|
|
];
|
|
|
|
boot.initrd.systemd.services.nomarchy-rollback = {
|
|
description = "Erase Your Darlings: roll the BTRFS root subvolume back to a blank snapshot";
|
|
wantedBy = [ "initrd.target" ];
|
|
after = [ "systemd-cryptsetup@${cfg.mainLuksName}.service" ];
|
|
before = [ "sysroot.mount" ];
|
|
unitConfig.DefaultDependencies = "no";
|
|
serviceConfig.Type = "oneshot";
|
|
script = ''
|
|
mkdir -p /btrfs_tmp
|
|
mount -o subvol=/ /dev/mapper/${cfg.mainLuksName} /btrfs_tmp
|
|
|
|
if [[ -e /btrfs_tmp/@ ]]; then
|
|
mkdir -p /btrfs_tmp/old_roots
|
|
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/@)" "+%Y-%m-%-d_%H:%M:%S")
|
|
mv /btrfs_tmp/@ "/btrfs_tmp/old_roots/$timestamp"
|
|
fi
|
|
|
|
delete_subvolume_recursively() {
|
|
IFS=$'\n'
|
|
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
|
|
delete_subvolume_recursively "/btrfs_tmp/$i"
|
|
done
|
|
btrfs subvolume delete "$1"
|
|
}
|
|
|
|
for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do
|
|
delete_subvolume_recursively "$i"
|
|
done
|
|
|
|
btrfs subvolume snapshot /btrfs_tmp/root-blank /btrfs_tmp/@
|
|
umount /btrfs_tmp
|
|
'';
|
|
};
|
|
|
|
# The impermanence module asserts that every filesystem it touches is
|
|
# available in early boot: the persistent-storage volume (/persist) and
|
|
# any volume it bind-mounts *into* — the user-persistence dirs land under
|
|
# /home, so the @home subvolume counts too. disko and
|
|
# nixos-generate-config leave neededForBoot at its default (false) on
|
|
# these subvolumes, which trips the assertion ("Please fix the following
|
|
# filesystems: /persist /home"). Declare it here, where the requirement
|
|
# originates.
|
|
fileSystems."/persist".neededForBoot = true;
|
|
fileSystems."/home".neededForBoot = true;
|
|
|
|
# 2. Persistence Configuration: What survives the wipe
|
|
environment.persistence."/persist" = {
|
|
hideMounts = true;
|
|
directories = [
|
|
"/var/log"
|
|
"/var/lib/nixos"
|
|
"/var/lib/systemd/coredump"
|
|
"/var/lib/NetworkManager"
|
|
"/etc/NetworkManager/system-connections"
|
|
"/var/lib/bluetooth"
|
|
"/var/lib/fprint"
|
|
"/etc/nixos"
|
|
"/etc/ssh"
|
|
];
|
|
files = [
|
|
"/etc/machine-id"
|
|
"/etc/supergfxd.conf"
|
|
];
|
|
users.${cfg.user} = {
|
|
directories = [
|
|
".ssh"
|
|
".gnupg"
|
|
".local/share/keyrings"
|
|
"Documents"
|
|
"Downloads"
|
|
"Pictures"
|
|
"Videos"
|
|
"Projects"
|
|
];
|
|
};
|
|
};
|
|
};
|
|
}
|