fruitbasket/modules/hedgedoc.nix

76 lines
2.1 KiB
Nix
Raw Normal View History

2022-09-06 15:09:30 +02:00
{ config, pkgs, lib, ... }:
2022-09-06 17:16:31 +02:00
let
2022-12-17 19:12:41 +01:00
domain = "pad.${config.fsr.domain}";
2022-09-06 17:16:31 +02:00
in
{
2022-09-06 15:09:30 +02:00
services = {
postgresql = {
enable = true;
ensureUsers = [
{
name = "hedgedoc";
ensurePermissions = {
"DATABASE hedgedoc" = "ALL PRIVILEGES";
};
}
];
ensureDatabases = [ "hedgedoc" ];
};
hedgedoc = {
enable = true;
2023-02-15 15:53:15 +01:00
settings = {
2022-09-06 15:09:30 +02:00
port = 3002;
domain = "${domain}";
protocolUseSSL = true;
dbURL = "postgres://hedgedoc:\${DB_PASSWORD}@localhost:5432/hedgedoc";
sessionSecret = "\${SESSION_SECRET}";
allowAnonymousEdits = true;
csp = {
enable = true;
directives = {
scriptSrc = "${domain}";
};
upgradeInsecureRequest = "auto";
addDefaults = true;
};
};
};
nginx = {
recommendedProxySettings = true;
virtualHosts = {
"${domain}" = {
enableACME = true;
forceSSL = true;
locations."/" = {
2023-02-15 15:53:15 +01:00
proxyPass = "http://[::1]:${toString config.services.hedgedoc.settings.port}";
2022-09-06 15:09:30 +02:00
proxyWebsockets = true;
};
};
};
};
};
sops.secrets.postgres_hedgedoc.owner = config.systemd.services.hedgedoc.serviceConfig.User;
sops.secrets.hedgedoc_session_secret.owner = config.systemd.services.hedgedoc.serviceConfig.User;
systemd.services.hedgedoc.preStart = lib.mkBefore ''
export DB_PASSWORD="$(cat ${config.sops.secrets.postgres_hedgedoc.path})"
export SESSION_SECRET="$(cat ${config.sops.secrets.hedgedoc_session_secret.path})"
'';
systemd.services.hedgedoc.after = [ "hedgedoc-pgsetup.service" ];
systemd.services.hedgedoc-pgsetup = {
description = "Prepare HedgeDoc postgres database";
wantedBy = [ "multi-user.target" ];
after = [ "networking.target" "postgresql.service" ];
serviceConfig.Type = "oneshot";
path = [ pkgs.sudo config.services.postgresql.package ];
script = ''
sudo -u ${config.services.postgresql.superUser} psql -c "ALTER ROLE hedgedoc WITH PASSWORD '$(cat ${config.sops.secrets.postgres_hedgedoc.path})'"
'';
};
}