initial commit
This commit is contained in:
commit
1efde7694d
22 changed files with 1038 additions and 0 deletions
49
modules/impermanence.nix
Normal file
49
modules/impermanence.nix
Normal 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
|
||||
'';
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue