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 (
i: attrs: let
mountpoint = builtins.getAttr "mountpoint" attrs; mountpoint = builtins.getAttr "mountpoint" attrs;
fs = builtins.getAttr mountpoint config.fileSystems; fs = builtins.getAttr mountpoint config.fileSystems;
in in
assert fs.fsType == "zfs"; assert fs.fsType == "zfs";
assert lib.assertMsg assert lib.assertMsg
config.mj.base.unitstatus.enable config.mj.base.unitstatus.enable
"config.mj.base.unitstatus.enable must be true"; { "config.mj.base.unitstatus.enable must be true";
name = lib.strings.sanitizeDerivationName mountpoint; lib.nameValuePair
value = "${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;
}; };
} }