borgbackup: add numbers to jobs

This commit is contained in:
Motiejus Jakštys 2023-09-11 17:33:16 +03:00
parent 5721531486
commit a522300158

View File

@ -61,16 +61,17 @@ in {
}; };
services.borgbackup.jobs = builtins.listToAttrs ( services.borgbackup.jobs = builtins.listToAttrs (
map (attrs: let lib.imap0 (
mountpoint = builtins.getAttr "mountpoint" attrs; i: attrs: let
fs = builtins.getAttr mountpoint config.fileSystems; mountpoint = builtins.getAttr "mountpoint" attrs;
in fs = builtins.getAttr mountpoint config.fileSystems;
assert fs.fsType == "zfs"; in
assert lib.assertMsg assert fs.fsType == "zfs";
config.mj.base.unitstatus.enable assert lib.assertMsg
"config.mj.base.unitstatus.enable must be true"; { config.mj.base.unitstatus.enable
name = lib.strings.sanitizeDerivationName mountpoint; "config.mj.base.unitstatus.enable must be true";
value = lib.nameValuePair
"${lib.strings.sanitizeDerivationName mountpoint}-${toString i}"
{ {
doInit = true; doInit = true;
repo = attrs.repo; repo = attrs.repo;
@ -97,14 +98,14 @@ in {
} }
// lib.optionalAttrs (sshKeyPath != null) { // lib.optionalAttrs (sshKeyPath != null) {
environment.BORG_RSH = ''ssh -i "${config.mj.base.zfsborg.sshKeyPath}"''; environment.BORG_RSH = ''ssh -i "${config.mj.base.zfsborg.sshKeyPath}"'';
}; }
}) )
dirs dirs
); );
mj.base.unitstatus.units = let mj.base.unitstatus.units = let
sanitized = map lib.strings.sanitizeDerivationName (lib.catAttrs "mountpoint" dirs); sanitized = map lib.strings.sanitizeDerivationName (lib.catAttrs "mountpoint" dirs);
in in
map (n: "borgbackup-job-${n}") sanitized; lib.imap0 (i: name: "borgbackup-job-${name}-${toString i}") sanitized;
}; };
} }