nix-config/modules/base/erase-your-darlings.nix
2026-03-24 01:57:19 +01:00

48 lines
1.1 KiB
Nix

{
inputs,
outputs,
lib,
config,
pkgs,
...
}: let
inherit (lib) mkEnableOption mkIf mkOption types;
cfg = config.horseman.base.erase-your-darlings;
in {
options = {
horseman.base.erase-your-darlings = {
enable = mkEnableOption "If set, assumes the machine has been set up as a Erase Your Darlings device";
};
};
config = mkIf cfg.enable {
environment.etc = {
nixos.source = "/persist/etc/nixos";
machine-id.source = "/persist/etc/machine-id";
};
security.sudo.extraConfig = ''
Defaults lecture = never
'';
boot.initrd.postDeviceCommands = pkgs.lib.mkBefore ''
mkdir -p /mnt
mount -o subvol=/ /dev/disk/by-label/ROOT /mnt
btrfs subvolume list -o /mnt/root |
cut -f9 -d' ' |
while read subvolume; do
echo "deleting /$subvolume subvolume..."
btrfs subvolume delete "/mnt/$subvolume"
done &&
echo "deleting /root subvolume..." &&
btrfs subvolume delete /mnt/root
echo "restoring blank /root subvolume..."
btrfs subvolume snapshot /mnt/root-blank /mnt/root
umount /mnt
'';
};
}