52 lines
1.3 KiB
Nix
52 lines
1.3 KiB
Nix
{
|
|
inputs,
|
|
outputs,
|
|
lib,
|
|
config,
|
|
pkgs,
|
|
...
|
|
}: let
|
|
inherit (lib) mkEnableOption mkIf mkOption types;
|
|
cfg = config.horseman.base.eraseYourDarlings;
|
|
in {
|
|
options = {
|
|
horseman.base.eraseYourDarlings = {
|
|
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";
|
|
"ssh/ssh_host_ed25519_key".source = "/persist/etc/ssh/ssh_host_ed25519_key";
|
|
"ssh/ssh_host_ed25519_key.pub".source = "/persist/etc/ssh/ssh_host_ed25519_key.pub";
|
|
};
|
|
|
|
security.sudo.extraConfig = ''
|
|
Defaults lecture = never
|
|
'';
|
|
|
|
users.mutableUsers = false;
|
|
|
|
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
|
|
'';
|
|
};
|
|
}
|