modules/rsync-pull-targets: fix multiple pull targets with same user

This commit is contained in:
h7x4
2026-01-27 21:10:17 +09:00
parent 949661113e
commit b77c8eb5c0

View File

@@ -124,16 +124,22 @@ in
services.openssh.enable = true; services.openssh.enable = true;
users.users = lib.pipe cfg.locations [ users.users = lib.pipe cfg.locations [
(lib.filterAttrs (_: value: value.enable)) (lib.filterAttrs (_: value: value.enable))
(lib.mapAttrs' (_: { user, location, rrsyncPackage, rrsyncArgs, authorizedKeysAttrs, publicKey, ... }: let
lib.attrValues
# Index locations by SSH user
(lib.foldl (acc: location: acc // {
${location.user} = (acc.${location.user} or [ ]) ++ [ location ];
}) { })
(lib.mapAttrs (_name: locations: {
openssh.authorizedKeys.keys = map ({ user, location, rrsyncPackage, rrsyncArgs, authorizedKeysAttrs, publicKey, ... }: let
rrsyncArgString = lib.cli.toCommandLineShellGNU { rrsyncArgString = lib.cli.toCommandLineShellGNU {
isLong = _: false; isLong = _: false;
} rrsyncArgs; } rrsyncArgs;
# TODO: handle " in location # TODO: handle " in location
in { in "command=\"${lib.getExe rrsyncPackage} ${rrsyncArgString} ${location}\",${lib.concatStringsSep "," authorizedKeysAttrs} ${publicKey}"
name = user; ) locations;
value.openssh.authorizedKeys.keys = [
"command=\"${lib.getExe rrsyncPackage} ${rrsyncArgString} ${location}\",${lib.concatStringsSep "," authorizedKeysAttrs} ${publicKey}"
];
})) }))
]; ];
}; };