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