summaryrefslogtreecommitdiff
path: root/modules/borgcopy/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/borgcopy/default.nix')
-rw-r--r--modules/borgcopy/default.nix120
1 files changed, 120 insertions, 0 deletions
diff --git a/modules/borgcopy/default.nix b/modules/borgcopy/default.nix
new file mode 100644
index 00000000..eae07dc8
--- /dev/null
+++ b/modules/borgcopy/default.nix
@@ -0,0 +1,120 @@
1{ config, pkgs, lib, utils, flakeInputs, ... }:
2
3with lib;
4
5let
6 copyBorg = flakeInputs.mach-nix.lib.${config.nixpkgs.system}.buildPythonPackage rec {
7 pname = "copy-borg";
8 src = ./copy;
9 version = "0.0.0";
10 ignoreDataOutdated = true;
11
12 requirements = ''
13 humanize
14 tqdm
15 python-dateutil
16 xdg
17 python-unshare
18 pyprctl
19 halo
20 '';
21 postInstall = ''
22 wrapProgram $out/bin/copy_borg \
23 --prefix PATH : ${makeBinPath (with pkgs; [util-linux borgbackup])}:${config.security.wrapperDir}
24 '';
25
26 providers.python-unshare = "nixpkgs";
27 overridesPre = [
28 (self: super: { python-unshare = super.python-unshare.overrideAttrs (oldAttrs: { name = "python-unshare-0.2.1"; version = "0.2.1"; }); })
29 ];
30
31 # _.tomli.buildInputs.add = with pkgs."python3Packages"; [ flit-core ];
32 };
33
34 copyService = name: opts: nameValuePair "copy-borg@${utils.escapeSystemdPath name}" {
35 serviceConfig = {
36 Type = "oneshot";
37 ExecStart = "${copyBorg}/bin/copy_borg --verbosity ${toString opts.verbosity} ${utils.escapeSystemdExecArgs [opts.from opts.to]}";
38 TimeoutStartSec = "8h";
39 # User = "borg";
40 # Group = "borg";
41 # StateDirectory = "borg";
42 RuntimeDirectory = "copy-borg";
43 Environment = [
44 "BORG_BASE_DIR=/var/lib/borg"
45 "BORG_CONFIG_DIR=/var/lib/borg/config"
46 "BORG_CACHE_DIR=/var/lib/borg/cache"
47 "BORG_SECURITY_DIR=/var/lib/borg/security"
48 "BORG_KEYS_DIR=/var/lib/borg/keys"
49 ]
50 ++ optional opts.unknownUnencryptedRepoAccessOk "BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes"
51 ++ optional opts.hostnameIsUnique "BORG_HOSTNAME_IS_UNIQUE=yes"
52 ++ optional (!(isNull opts.sshConfig)) "BORG_RSH=\"${pkgs.openssh}/bin/ssh -F ${pkgs.writeText "config" opts.sshConfig}\""
53 ++ optional (!(isNull opts.keyfile)) "BORG_KEY_FILE=${opts.keyfile}";
54
55 LogRateLimitIntervalSec = 0;
56 };
57 };
58 copyTimer = name: opts: nameValuePair "copy-borg@${utils.escapeSystemdPath name}" (recursiveUpdate {
59 wantedBy = [ "timers.target" ];
60
61 timerConfig = {
62 Unit = "copy-borg@${utils.escapeSystemdPath name}.service";
63 };
64 } opts.timerOptions);
65
66 cfg = config.services.copyborg;
67in {
68 options = {
69 services.copyborg = mkOption {
70 type = types.attrsOf (types.submodule {
71 options = {
72 from = mkOption {
73 type = types.str;
74 };
75 to = mkOption {
76 type = types.str;
77 };
78
79 verbosity = mkOption {
80 type = types.int;
81 default = 3;
82 };
83
84 sshConfig = mkOption {
85 type = with types; nullOr str;
86 default = null;
87 };
88
89 keyfile = mkOption {
90 type = with types; nullOr str;
91 default = null;
92 };
93
94 unknownUnencryptedRepoAccessOk = mkOption {
95 type = types.bool;
96 default = false;
97 };
98 hostnameIsUnique = mkOption {
99 type = types.bool;
100 default = true;
101 };
102
103 timerOptions = mkOption {
104 # type = types.submodule utils.systemdUtils.unitOptions.stage2TimerOptions;
105 type = types.attrs;
106 default = {
107 wantedBy = ["timers.target"];
108 };
109 };
110 };
111 });
112 default = {};
113 };
114 };
115
116 config = {
117 systemd.services = mapAttrs' copyService cfg;
118 systemd.timers = mapAttrs' copyTimer cfg;
119 };
120}