2016-04-21 22:45:06 +02:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2018-02-27 16:31:16 +01:00
|
|
|
service-keys = config.services.tor.service-keys;
|
|
|
|
torDir = "/var/lib/tor";
|
2016-04-21 22:45:06 +02:00
|
|
|
in {
|
2018-02-27 16:31:16 +01:00
|
|
|
options.services.tor.service-keys = mkOption {
|
2021-05-29 18:05:31 +02:00
|
|
|
default = { };
|
2021-01-03 16:43:55 +01:00
|
|
|
type = with types; attrsOf str;
|
2016-04-21 22:45:06 +02:00
|
|
|
};
|
|
|
|
|
2021-05-29 18:05:31 +02:00
|
|
|
config = mkIf (service-keys != { }) {
|
2016-04-21 22:45:06 +02:00
|
|
|
systemd.services."install-tor-hidden-service-keys" = {
|
2021-05-29 18:05:31 +02:00
|
|
|
wantedBy = [ "tor.service" ];
|
2016-04-21 22:45:06 +02:00
|
|
|
serviceConfig.Type = "oneshot";
|
2018-03-11 23:17:55 +01:00
|
|
|
serviceConfig.User = "root";
|
2016-04-21 22:45:06 +02:00
|
|
|
serviceConfig.Group = "keys";
|
|
|
|
# TODO: update on change?
|
|
|
|
# TODO: better ways to get the keys on the server
|
2018-02-27 16:31:16 +01:00
|
|
|
script = concatStringsSep "\n" (mapAttrsToList (name: keypath: ''
|
|
|
|
if ! [[ -e ${torDir}/onion/${name}/private_key ]]; then
|
|
|
|
mkdir -p ${torDir}/onion/${name}/
|
|
|
|
cp ${keypath} ${torDir}/onion/${name}/private_key
|
|
|
|
chmod -R 700 ${torDir}/onion/${name}
|
2018-03-11 23:17:55 +01:00
|
|
|
chown -R tor ${torDir}/onion/${name}
|
2016-04-21 22:45:06 +02:00
|
|
|
fi
|
2018-02-27 16:31:16 +01:00
|
|
|
'') service-keys);
|
2016-04-21 22:45:06 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|