tidy up piped backend.nix module

This commit is contained in:
Chaos 2022-12-03 17:17:36 +00:00
parent d7be51ac65
commit e2a2608a2b
No known key found for this signature in database

View file

@ -23,23 +23,21 @@ let
"hibernate.dialect" = "org.hibernate.dialect.PostgreSQLDialect";
"hibernate.connection.username" = "piped";
"hibernate.connection.password" = "password";
} // (if cfg.enableCaptcha then {
} // (optionalAttrs cfg.enableCaptcha {
CAPTCHA_API_URL = cfg.captchaAPIURL;
# This is substituted in the PreStart of piped-backend.service
CAPTCHA_API_KEY = if cfg.captchaAPIKeyFile != "" then
"CAPTCHA_API_KEY_FILE"
else
cfg.captchaAPIKey;
} else
{ }) // (if cfg.enableFederation then {
}) // (optionalAttrs cfg.enableFederation {
MATRIX_SERVER = cfg.matrixServerAddr;
# also substituted
MATRIX_TOKEN = if cfg.matrixTokenFile != "" then
"MATRIX_TOKEN_FILE"
else
cfg.matrixToken;
} else
{ });
});
cfgToString = v: if builtins.isBool v then boolToString v else toString v;
backend_config_file = pkgs.writeText "config.properties"
@ -59,14 +57,13 @@ in {
[ -f "${confFile}" ] && rm ${confFile}
cp ${backend_config_file} ${confFile}
chmod 660 ${confFile}
${if (cfg.enableCaptcha && cfg.captchaAPIKeyFile != "") then ''
${optionalString (cfg.enableCaptcha && cfg.captchaAPIKeyFile != "") ''
sed -i "s/CAPTCHA_API_KEY_FILE/$(cat cfg.captchaAPIKeyFile | sed "s#/#\\\/#")/" ${confFile}
'' else
""}
${if (cfg.enableFederation && cfg.matrixTokenFile != "") then ''
''}
${optionalString
(cfg.enableFederation && cfg.matrixTokenFile != "") ''
sed -i "s/MATRIX_TOKEN_FILE/$(cat cfg.matrixTokenFile | sed "s#/#\\\/#")/" ${confFile}
'' else
""}
''}
''}";
ExecStart = "${pkgs.piped-backend}/bin/piped-backend";