summaryrefslogtreecommitdiff
path: root/hosts/vidhar/zfs.nix
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2022-02-19 15:05:25 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2022-02-19 15:05:25 +0100
commit6f82f965a742d2013d9bab578a4d83fa37526902 (patch)
tree33809fa53d7b8c71d2ebd0f88f90e23c738f3616 /hosts/vidhar/zfs.nix
parente3ae43ac32b6d267dcb6acfa1dd5256136b4656b (diff)
downloadnixos-6f82f965a742d2013d9bab578a4d83fa37526902.tar
nixos-6f82f965a742d2013d9bab578a4d83fa37526902.tar.gz
nixos-6f82f965a742d2013d9bab578a4d83fa37526902.tar.bz2
nixos-6f82f965a742d2013d9bab578a4d83fa37526902.tar.xz
nixos-6f82f965a742d2013d9bab578a4d83fa37526902.zip
vidhar: zfssnap...
Diffstat (limited to 'hosts/vidhar/zfs.nix')
-rw-r--r--hosts/vidhar/zfs.nix62
1 files changed, 2 insertions, 60 deletions
diff --git a/hosts/vidhar/zfs.nix b/hosts/vidhar/zfs.nix
index f5a0383a..bee4e88a 100644
--- a/hosts/vidhar/zfs.nix
+++ b/hosts/vidhar/zfs.nix
@@ -1,32 +1,5 @@
1{ pkgs, lib, config, ... }: 1{ pkgs, lib, 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 "/boot" = 5 "/boot" =
@@ -136,38 +109,7 @@ in {
136 echo "=== ZPOOL IMPORT COMPLETE ===" 109 echo "=== ZPOOL IMPORT COMPLETE ==="
137 ''; 110 '';
138 111
139 systemd.services = 112 services.zfssnap.enable = true;
140 let mkSnapService = snapName: {
141 name = "zfs-snapshot-${snapName}";
142 value = {
143 description = "ZFS auto-snapshot every ${snapshotDescr.${snapName}}";
144 after = [ "zfs-import.target" ];
145 serviceConfig = {
146 Type = "oneshot";
147 ExecStart = "${autosnapPackage}/bin/zfs-auto-snapshot -k -p -u ${snapName} ${toString snapshotCount.${snapName}}";
148 };
149 restartIfChanged = false;
150
151 preStart = ''
152 ${zfs}/bin/zfs set com.sun:auto-snapshot=true hdd-raid6/safe
153 ${zfs}/bin/zfs set com.sun:auto-snapshot=false hdd-raid6/safe/home/mherold/eos/base
154 ${zfs}/bin/zfs set com.sun:auto-snapshot=true ssd-raid1/safe
155 ${zfs}/bin/zfs set com.sun:auto-snapshot=true boot
156 '';
157 };
158 };
159 in builtins.listToAttrs (map mkSnapService snapshotNames);
160
161 systemd.timers =
162 let mkSnapTimer = snapName: {
163 name = "zfs-snapshot-${snapName}";
164 value = {
165 wantedBy = [ "timers.target" ];
166 timerConfig = snapshotTimerConfig.${snapName};
167 };
168 };
169 in builtins.listToAttrs (map mkSnapTimer snapshotNames);
170
171 services.zfs.trim.enable = false; 113 services.zfs.trim.enable = false;
172 services.zfs.autoScrub = { 114 services.zfs.autoScrub = {
173 enable = true; 115 enable = true;