mirror of
https://git.sr.ht/~magic_rb/dotfiles
synced 2024-12-12 18:01:59 +01:00
83 lines
2 KiB
Nix
83 lines
2 KiB
Nix
|
{
|
||
|
inputs',
|
||
|
pkgs,
|
||
|
...
|
||
|
}: let
|
||
|
rollbackStart = pkgs.writeText "rollback-start" ''
|
||
|
${pkgs.rolling_datasets}/bin/roll_dataset "heater-ssd/ephemeral/home" "10"
|
||
|
${pkgs.rolling_datasets}/bin/roll_dataset "heater-ssd/ephemeral/root" "10"
|
||
|
${pkgs.rolling_datasets}/bin/roll_dataset "heater-ssd/ephemeral/nix-tmp" "10"
|
||
|
'';
|
||
|
in {
|
||
|
nixpkgs.overlays = [
|
||
|
inputs'.self.overlays.show-files-to-be-deleted
|
||
|
inputs'.self.overlays.rolling_datasets
|
||
|
];
|
||
|
|
||
|
environment.systemPackages = [
|
||
|
pkgs.show-files-to-be-deleted
|
||
|
];
|
||
|
|
||
|
environment.persistence."/nix/persist" = {
|
||
|
hideMounts = true;
|
||
|
|
||
|
directories = [
|
||
|
"/var/log"
|
||
|
"/var/lib/nixos"
|
||
|
"/var/lib/systemd/coredump"
|
||
|
];
|
||
|
files = [
|
||
|
"/etc/machine-id"
|
||
|
"/etc/ssh/ssh_host_rsa_key"
|
||
|
"/etc/ssh/ssh_host_rsa_key.pub"
|
||
|
"/etc/ssh/ssh_host_ed25519_key"
|
||
|
"/etc/ssh/ssh_host_ed25519_key.pub"
|
||
|
];
|
||
|
};
|
||
|
|
||
|
boot.initrd.systemd.storePaths = with pkgs; [
|
||
|
zfs
|
||
|
busybox
|
||
|
rolling_datasets
|
||
|
rollbackStart
|
||
|
];
|
||
|
boot.initrd.systemd.services.rollback = {
|
||
|
description = "Rollback ZFS datasets to a pristine state";
|
||
|
wantedBy = [
|
||
|
"initrd.target"
|
||
|
];
|
||
|
after = [
|
||
|
"zfs-import-heater-ssd.service"
|
||
|
];
|
||
|
before = [
|
||
|
"sysroot.mount"
|
||
|
];
|
||
|
path = with pkgs; [
|
||
|
zfs
|
||
|
busybox
|
||
|
];
|
||
|
unitConfig.DefaultDependencies = "no";
|
||
|
serviceConfig.Type = "oneshot";
|
||
|
serviceConfig.ExecStart = "/bin/sh ${rollbackStart}";
|
||
|
};
|
||
|
|
||
|
systemd.services."mount-old-datasets" = {
|
||
|
description = "Mount old versions of datasets";
|
||
|
|
||
|
wantedBy = ["local-fs.target"];
|
||
|
after = ["local-fs.target"];
|
||
|
|
||
|
script = ''
|
||
|
${pkgs.rolling_datasets}/bin/mount_datasets "heater-ssd/ephemeral/home" "/home/.old"
|
||
|
${pkgs.rolling_datasets}/bin/mount_datasets "heater-ssd/ephemeral/root" "/root/.old"
|
||
|
${pkgs.rolling_datasets}/bin/mount_datasets "heater-ssd/ephemeral/nix-tmp" "/nix/tmp/.old"
|
||
|
'';
|
||
|
|
||
|
serviceConfig = {
|
||
|
Type = "oneshot";
|
||
|
RemainAfterExit = "yes";
|
||
|
TimeoutStartSec = "5m";
|
||
|
};
|
||
|
};
|
||
|
}
|