summaryrefslogtreecommitdiff
path: root/hosts
diff options
context:
space:
mode:
Diffstat (limited to 'hosts')
-rw-r--r--hosts/surtr/zfs.nix59
1 files changed, 2 insertions, 57 deletions
diff --git a/hosts/surtr/zfs.nix b/hosts/surtr/zfs.nix
index 3e42ef3e..3a69fd96 100644
--- a/hosts/surtr/zfs.nix
+++ b/hosts/surtr/zfs.nix
@@ -1,32 +1,5 @@
1{ pkgs, config, ... }: 1{ pkgs, config, ... }:
2let 2{
3 snapshotNames = ["frequent" "hourly" "daily" "monthly" "yearly"];
4 snapshotCount = {
5 frequent = 24;
6 hourly = 24;
7 daily = 30;
8 monthly = 12;
9 yearly = 5;
10 };
11 snapshotTimerConfig = {
12 frequent = { OnCalendar = "*:0/5 UTC"; Persistent = true; };
13 hourly = { OnCalendar = "hourly UTC"; Persistent = true; };
14 daily = { OnCalendar = "daily UTC"; Persistent = true; };
15 monthly = { OnCalendar = "monthly UTC"; Persistent = true; };
16 yearly = { OnCalendar = "yearly UTC"; Persistent = true; };
17 };
18 snapshotDescr = {
19 frequent = "few minutes";
20 hourly = "hour";
21 daily = "day";
22 monthly = "month";
23 yearly = "year";
24 };
25
26 zfs = config.boot.zfs.package;
27
28 autosnapPackage = pkgs.zfstools.override { inherit zfs; };
29in {
30 config = { 3 config = {
31 fileSystems = { 4 fileSystems = {
32 "/nix" = 5 "/nix" =
@@ -69,35 +42,7 @@ in {
69 }; 42 };
70 }; 43 };
71 44
72 systemd.services = 45 services.zfssnap.enable = true;
73 let mkSnapService = snapName: {
74 name = "zfs-snapshot-${snapName}";
75 value = {
76 description = "ZFS auto-snapshot every ${snapshotDescr.${snapName}}";
77 after = [ "zfs-import.target" ];
78 serviceConfig = {
79 Type = "oneshot";
80 ExecStart = "${autosnapPackage}/bin/zfs-auto-snapshot -k -p -u ${snapName} ${toString snapshotCount.${snapName}}";
81 };
82 restartIfChanged = false;
83
84 preStart = ''
85 ${zfs}/bin/zfs set com.sun:auto-snapshot=true surtr/safe
86 '';
87 };
88 };
89 in builtins.listToAttrs (map mkSnapService snapshotNames);
90
91 systemd.timers =
92 let mkSnapTimer = snapName: {
93 name = "zfs-snapshot-${snapName}";
94 value = {
95 wantedBy = [ "timers.target" ];
96 timerConfig = snapshotTimerConfig.${snapName};
97 };
98 };
99 in builtins.listToAttrs (map mkSnapTimer snapshotNames);
100
101 services.zfs.trim.enable = false; 46 services.zfs.trim.enable = false;
102 services.zfs.autoScrub = { 47 services.zfs.autoScrub = {
103 enable = true; 48 enable = true;