]> Git — Sourcephile - sourcephile-nix.git/blob - hosts/mermet/sanoid.nix
losurdo: enable nix-serve only over wg-intra
[sourcephile-nix.git] / hosts / mermet / sanoid.nix
1 { pkgs, lib, config, inputs, ... }:
2 let
3 inherit (builtins) readFile;
4 inherit (config.users) users groups;
5 in
6 {
7 users.users.backup = {
8 isSystemUser = true;
9 shell = users.root.shell;
10 group = groups.disk.name;
11 openssh.authorizedKeys.keys = [
12 (readFile (inputs.secrets + "/hosts/losurdo/ssh/backup.ssh-ed25519.pub"))
13 ] ++ users."julm".openssh.authorizedKeys.keys;
14 };
15 systemd.tmpfiles.rules = [
16 "z /dev/zfs 0660 - ${groups."disk".name} -"
17 ];
18 system.activationScripts.backup = ''
19 # This one should not be necessary
20 /run/booted-system/sw/bin/zfs allow -u ${users.backup.name} bookmark,hold,send rpool
21 /run/booted-system/sw/bin/zfs allow -u ${users.backup.name} receive,create,mount,rollback rpool/backup
22 '';
23
24 systemd.services.sanoid.serviceConfig.SupplementaryGroups = [ groups."disk".name ];
25 services.sanoid = {
26 enable = true;
27 templates = {
28 snap = {
29 autosnap = true;
30 autoprune = true;
31 monthly = 3;
32 };
33 prune = {
34 autosnap = false;
35 autoprune = true;
36 monthly = 3;
37 };
38 };
39 extraArgs = [
40 "--verbose"
41 #"--debug"
42 ];
43 datasets = {
44 "rpool/backup/losurdo/var/postgresql" = {
45 use_template = [ "prune" ];
46 daily = 31;
47 };
48 "rpool/backup/losurdo/var/cryptpad" = {
49 use_template = [ "prune" ];
50 daily = 31;
51 monthly = 0;
52 };
53 };
54 };
55 }