]> Git — Sourcephile - julm/julm-nix.git/blob - hosts/pumpkin/syncoid.nix
nix: format with nixfmt-rfc-style
[julm/julm-nix.git] / hosts / pumpkin / syncoid.nix
1 {
2 pkgs,
3 lib,
4 config,
5 inputs,
6 hostName,
7 ...
8 }:
9 let
10 inherit (config.users) users;
11 pumpkin2off2 =
12 conf:
13 lib.mapAttrs (_n: v: lib.recursiveUpdate v conf) {
14 "pumpkin/root" =
15 let
16 targetHost = "aubergine.local";
17 in
18 {
19 target = "backup@${targetHost}:off2/julm/backup/pumpkin";
20 sendOptions = "raw";
21 recursive = true;
22 extraArgs = [
23 "--create-bookmark"
24 "--no-sync-snap"
25 "--no-privilege-elevation"
26 "--preserve-properties"
27 "--preserve-recordsize"
28 "--recursive"
29 "--sendoptions=w"
30 "--recvoptions=u"
31 "--exclude"
32 "pumpkin/root/nix"
33 "--exclude"
34 "pumpkin/root/var/cache"
35 "--exclude"
36 "pumpkin/root/var/log"
37 "--exclude"
38 "pumpkin/root/home/julm/.cache"
39 "--sshconfig"
40 "${pkgs.writeText "ssh-config" ''
41 Host *
42 Ciphers aes128-gcm@openssh.com
43 Compression no
44 StrictHostKeyChecking yes
45 UserKnownHostsFile ${pkgs.writeText "known_hosts" ''
46 ${targetHost} ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN/cT/L3dF7uoR3s7NB59NiKjuk35I6x+7MK5zhwOy6k
47 ''}
48 ''}"
49 ];
50 };
51 };
52 in
53 {
54 networking.nftables.ruleset = lib.mkAfter ''
55 table inet filter {
56 chain output-net {
57 skuid @nixos_syncoid_uids \
58 meta l4proto tcp \
59 counter accept \
60 comment "syncoid: SSH"
61 }
62 }
63 '';
64 systemd.tmpfiles.rules = [
65 "z /dev/zfs 0660 - ${config.users.groups."disk".name} -"
66 ];
67 # ExplanationNote: give access to /var/run/avahi-daemon/socket
68 # Using /var/run is not working due to RootDirectoryStartOnly=true
69 systemd.services.syncoid-pumpkin-root.serviceConfig.BindReadOnlyPaths = [ "/var/run" ];
70 systemd.services.syncoid-pumpkin-root.serviceConfig.RootDirectoryStartOnly = lib.mkForce false;
71 systemd.services.syncoid-pumpkin-root.serviceConfig.ExecStartPost =
72 pkgs.writeShellScript "zfs-fix-bookmarks" ''
73 set -ux
74 for s in $(zfs list -Hrpt snapshot -o name pumpkin); do
75 zfs bookmark "$s" "''${s//@/#}" || true
76 done
77 '';
78 services.syncoid = {
79 enable = true;
80 interval = "*-*-* *:05:00";
81 #interval = "*:0/1";
82 sshKey = "ssh.key:${syncoid/ssh.key.cred}";
83 commonArgs = [
84 #"--debug"
85 "--no-sync-snap"
86 "--create-bookmark"
87 #"--no-privilege-elevation"
88 #"--no-stream"
89 #"--preserve-recordsize"
90 #"--preserve-properties"
91 ];
92 service = {
93 serviceConfig.Group = config.users.groups."disk".name;
94 };
95 commands = { } // pumpkin2off2 { };
96 };
97 }