From 4a92828efb24de519fd8ce1f6633eb7b77221c6c Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Mon, 25 Nov 2024 08:03:59 +0000 Subject: [PATCH] Replace backintime with rsnapshot --- nix/lib/nixos/configuration.nix | 1 - nix/modules/nixos/default.nix | 1 + nix/modules/nixos/desktop/steam.nix | 0 nix/modules/nixos/rsnapshot.nix | 70 +++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 nix/modules/nixos/desktop/steam.nix create mode 100644 nix/modules/nixos/rsnapshot.nix diff --git a/nix/lib/nixos/configuration.nix b/nix/lib/nixos/configuration.nix index e762fdb..4bbe0ce 100644 --- a/nix/lib/nixos/configuration.nix +++ b/nix/lib/nixos/configuration.nix @@ -156,7 +156,6 @@ ++ pkgs.lib.optionals desktop [ acpi arandr - backintime bluetuith brightnessctl cpufrequtils diff --git a/nix/modules/nixos/default.nix b/nix/modules/nixos/default.nix index d21b3cb..0ee96bd 100644 --- a/nix/modules/nixos/default.nix +++ b/nix/modules/nixos/default.nix @@ -2,5 +2,6 @@ imports = [ ./docker.nix ./kanata.nix + ./rsnapshot.nix ]; } diff --git a/nix/modules/nixos/desktop/steam.nix b/nix/modules/nixos/desktop/steam.nix new file mode 100644 index 0000000..e69de29 diff --git a/nix/modules/nixos/rsnapshot.nix b/nix/modules/nixos/rsnapshot.nix new file mode 100644 index 0000000..3e043e6 --- /dev/null +++ b/nix/modules/nixos/rsnapshot.nix @@ -0,0 +1,70 @@ +{ pkgs, ... }: + +let + backups1 = { + path = "/mnt/backup"; + uuid = "fd47c61a-8aac-44ed-9a18-4ec43ee663fb"; + }; +in +{ + systemd = { + mounts = [ + { + where = "${backups1.path}"; + what = "UUID=${backups1.uuid}"; + type = "ext4"; + options = "defaults,noatime,nofail"; + } + ]; + + automounts = [ + { + where = "${backups1.path}"; + automountConfig.TimeoutIdleSec = "60"; + } + ]; + }; + + systemd.tmpfiles.rules = [ + "d ${backups1.path} 755 root root -" + ]; + + services = { + udev.extraRules = '' + ACTION=="add", SUBSYSTEM=="block", ENV{ID_FS_UUID}=="${backups1.uuid}", ENV{SYSTEMD_WANTS}="mnt-backup.mount" + ACTION=="remove", SUBSYSTEM=="block", ENV{ID_FS_UUID}=="${backups1.uuid}", RUN+="${pkgs.systemd}/bin/systemctl stop mnt-backup.mount" + ''; + + rsnapshot = { + enable = true; + enableManualRsnapshot = true; + + extraConfig = '' + lockfile /home/opdavies/.rsnapshot.pid + + snapshot_root /mnt/backup/rsnapshot/ + no_create_root 1 + + backup /home/opdavies opdavies/ + backup /media media/ + backup /var/lib/immich/upload immich/ + + exclude ".cache/" + exclude ".devenv/" + exclude ".direnv/" + exclude "node_modules/" + exclude "vendor/" + + retain daily 7 + retain weekly 4 + retain monthly 12 + ''; + + cronIntervals = { + daily = "0 21 * * *"; + monthly = "0 23 1 * 0"; + weekly = "0 22 * * 0"; + }; + }; + }; +}