initial commit

This commit is contained in:
Jakob Lechner 2025-07-17 00:45:59 +02:00
commit 1efde7694d
22 changed files with 1038 additions and 0 deletions

49
modules/impermanence.nix Normal file
View file

@ -0,0 +1,49 @@
{
config,
lib,
...
}: {
options.weinturm = with lib; {
impermanence = {
enable = mkOption {
type = types.bool;
default = true;
description = "Whether to enable impermanence";
};
rootDevice = with types;
mkOption {
type = nullOr str;
default = null;
description = ''
The device which contains the btrfs root subvolume
'';
};
};
};
config = let
cfg = config.weinturm.impermanence;
in
lib.mkIf cfg.enable {
fileSystems."/persist".neededForBoot = true;
environment.persistence."/persist".directories = [
"/var/lib/nixos"
];
boot.initrd.postDeviceCommands = let
rootDevice =
if cfg.rootDevice == null
then ""
else cfg.rootDevice;
in
lib.mkAfter ''
mkdir /mnt
mount -t btrfs "${rootDevice}" /mnt
btrfs subvolume list -o /mnt/root | cut -f9 -d' ' | while read subvolume; do
btrfs subvolume delete "/mnt/$subvolume"
done
btrfs subvolume delete /mnt/root
btrfs subvolume snapshot /mnt/root-blank /mnt/root
'';
};
}