diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2023-03-13 15:42:35 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2023-03-13 15:42:35 +0100 |
commit | 6e820741126c9c8b156cf8f9fe285e96cafb3138 (patch) | |
tree | de2b4aeaff584420f2410ce47e0f906f68e79387 /modules/zfssnap/default.nix | |
parent | b9e6f77db0871da3c72928619395590b28ea0181 (diff) | |
download | nixos-6e820741126c9c8b156cf8f9fe285e96cafb3138.tar nixos-6e820741126c9c8b156cf8f9fe285e96cafb3138.tar.gz nixos-6e820741126c9c8b156cf8f9fe285e96cafb3138.tar.bz2 nixos-6e820741126c9c8b156cf8f9fe285e96cafb3138.tar.xz nixos-6e820741126c9c8b156cf8f9fe285e96cafb3138.zip |
spin off backup-utils
Diffstat (limited to 'modules/zfssnap/default.nix')
-rw-r--r-- | modules/zfssnap/default.nix | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/modules/zfssnap/default.nix b/modules/zfssnap/default.nix deleted file mode 100644 index 23041c36..00000000 --- a/modules/zfssnap/default.nix +++ /dev/null | |||
@@ -1,113 +0,0 @@ | |||
1 | { config, pkgs, lib, flakeInputs, ... }: | ||
2 | |||
3 | with lib; | ||
4 | |||
5 | let | ||
6 | zfssnap = flakeInputs.mach-nix.lib.${config.nixpkgs.system}.buildPythonPackage rec { | ||
7 | pname = "zfssnap"; | ||
8 | src = ./zfssnap; | ||
9 | version = "0.0.0"; | ||
10 | ignoreDataOutdated = true; | ||
11 | |||
12 | requirements = '' | ||
13 | pyxdg | ||
14 | pytimeparse | ||
15 | python-dateutil | ||
16 | ''; | ||
17 | postInstall = '' | ||
18 | wrapProgram $out/bin/zfssnap \ | ||
19 | --prefix PATH : ${makeBinPath [config.boot.zfs.package]} | ||
20 | ''; | ||
21 | }; | ||
22 | |||
23 | cfg = config.services.zfssnap; | ||
24 | in { | ||
25 | options = { | ||
26 | services.zfssnap = { | ||
27 | enable = mkEnableOption "zfssnap service"; | ||
28 | |||
29 | config = mkOption { | ||
30 | type = types.submodule { | ||
31 | options = { | ||
32 | keep = mkOption { | ||
33 | type = with types; attrsOf str; | ||
34 | default = { | ||
35 | within = "15m"; | ||
36 | "5m" = "48"; | ||
37 | "15m" = "32"; | ||
38 | hourly = "48"; | ||
39 | "4h" = "24"; | ||
40 | "12h" = "12"; | ||
41 | daily = "62"; | ||
42 | halfweekly = "32"; | ||
43 | weekly = "24"; | ||
44 | monthly = "-1"; | ||
45 | }; | ||
46 | }; | ||
47 | exec = mkOption { | ||
48 | type = with types; attrsOf str; | ||
49 | default = {}; | ||
50 | }; | ||
51 | }; | ||
52 | }; | ||
53 | }; | ||
54 | |||
55 | snapInterval = mkOption { | ||
56 | type = types.str; | ||
57 | default = "*-*-* *:00/5:00"; | ||
58 | }; | ||
59 | |||
60 | verbosity = mkOption { | ||
61 | type = types.int; | ||
62 | default = 2; | ||
63 | }; | ||
64 | |||
65 | extraPruneArgs = mkOption { | ||
66 | type = with types; listOf str; | ||
67 | default = []; | ||
68 | }; | ||
69 | extraAutosnapArgs = mkOption { | ||
70 | type = with types; listOf str; | ||
71 | default = []; | ||
72 | }; | ||
73 | }; | ||
74 | }; | ||
75 | |||
76 | config = mkIf cfg.enable { | ||
77 | systemd.services."zfssnap" = { | ||
78 | description = "Create automatic ZFS snapshots"; | ||
79 | after = [ "zfs-import.target" ]; | ||
80 | wants = [ "zfssnap-prune.service" ]; | ||
81 | before = [ "zfssnap-prune.service" ]; | ||
82 | serviceConfig = { | ||
83 | Type = "oneshot"; | ||
84 | ExecStart = "${zfssnap}/bin/zfssnap --verbosity=${toString cfg.verbosity} autosnap ${escapeShellArgs cfg.extraAutosnapArgs}"; | ||
85 | |||
86 | LogRateLimitIntervalSec = 0; | ||
87 | }; | ||
88 | }; | ||
89 | systemd.services."zfssnap-prune" = { | ||
90 | description = "Prune automatic ZFS snapshots"; | ||
91 | after = [ "zfs-import.target" "zfssnap.service" ]; | ||
92 | serviceConfig = { | ||
93 | Type = "oneshot"; | ||
94 | ExecStart = let | ||
95 | mkSectionName = name: strings.escape [ "[" "]" ] (strings.toUpper name); | ||
96 | zfssnapConfig = generators.toINI { inherit mkSectionName; } cfg.config; | ||
97 | in "${zfssnap}/bin/zfssnap --verbosity=${toString cfg.verbosity} prune --config=${pkgs.writeText "zfssnap.ini" zfssnapConfig} ${escapeShellArgs cfg.extraPruneArgs}"; | ||
98 | |||
99 | LogRateLimitIntervalSec = 0; | ||
100 | }; | ||
101 | }; | ||
102 | |||
103 | systemd.timers."zfssnap" = { | ||
104 | wantedBy = ["timers.target"]; | ||
105 | timerConfig = { | ||
106 | OnCalendar = cfg.snapInterval; | ||
107 | Persistent = true; | ||
108 | }; | ||
109 | }; | ||
110 | |||
111 | environment.systemPackages = [zfssnap]; | ||
112 | }; | ||
113 | } | ||