Disable home impermanence

This commit is contained in:
Madeleine Sydney
2024-12-21 09:49:20 -07:00
parent 684e78e936
commit be5341b5b1
12 changed files with 594 additions and 262 deletions

View File

@@ -20,6 +20,11 @@ in {
default = [];
};
persistGroupName = mkOption {
default = "persist";
type = types.str;
};
files = mkOption {
description = "";
@@ -45,10 +50,28 @@ in {
};
config = mkIf cfg.enable {
users.groups.${cfg.persistGroupName} = {
name = cfg.persistGroupName;
};
systemd.tmpfiles.settings = {
"10-persist" = {
"/persist" = {
z = {
group = cfg.persistGroupName;
mode = "2775";
};
};
};
};
boot.initrd.systemd.initrdBin = with pkgs; [
zfs
];
# TODO: Move this somewhere else.
programs.fuse.userAllowOther = true;
boot.initrd.systemd.services.erase-darlings =
let service = {
description = "Rollback filesystem to a blank state on boot";
@@ -77,28 +100,35 @@ in {
then service
else throw "sydnix.impermanence currently requires config.boot.initrd.systemd.enable'!";
systemd.services.erase-home-darlings = {
description = "Rollback home to a blank state on boot";
wantedBy = [
"multi-user.target"
];
after = [
"home.mount"
];
path = [ pkgs.zfs pkgs.babashka ];
# unitConfig.DefaultDependencies = "no";
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart =
let script = ./erase-home-darlings.clj;
in ''${pkgs.babashka}/bin/bb "${script}" -n "${toString cfg.archiveLimit}" --dataset "${cfg.dataset}" --rollback-to "${cfg.rollbackTo}"'';
systemd.services =
let erase-home-darlings = {
description = "Rollback home to a blank state on boot";
wantedBy = [
"local-fs-pre.target"
"zfs-mount.service"
];
before = [
"local-fs.target"
"local-fs-pre.target"
"zfs-mount.service"
];
path = [ pkgs.zfs pkgs.babashka pkgs.util-linux ];
unitConfig.DefaultDependencies = "no";
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart =
let script = ./erase-home-darlings.clj;
in ''${pkgs.babashka}/bin/bb "${script}" -n "${toString cfg.archiveLimit}" --dataset "${cfg.dataset}" --rollback-to "${cfg.rollbackTo}"'';
};
stopIfChanged = false;
restartIfChanged = false;
};
in {
# inherit erase-home-darlings;
};
stopIfChanged = false;
restartIfChanged = false;
};
environment.persistence."/persist" = {
environment.persistence."/persist/root" = {
directories = cfg.directories;
files = cfg.files;
};