2021-03-10 15:40:55 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.services.hedgedoc;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
|
|
|
ensureDatabases = [ "hedgedoc" ];
|
|
|
|
ensureUsers = lib.singleton {
|
2022-03-22 18:54:59 +01:00
|
|
|
name = "codimd";
|
2021-03-10 15:40:55 +01:00
|
|
|
ensurePermissions = {
|
|
|
|
"DATABASE hedgedoc" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.hedgedoc = {
|
|
|
|
enable = true;
|
|
|
|
configuration = {
|
|
|
|
host = "127.0.0.1";
|
|
|
|
port = 3001;
|
|
|
|
db = {
|
|
|
|
dialect = "postgres";
|
|
|
|
host = "/run/postgresql";
|
2022-03-22 18:54:59 +01:00
|
|
|
#user = "hedgedoc";
|
2021-03-10 15:40:55 +01:00
|
|
|
database = "hedgedoc";
|
|
|
|
};
|
|
|
|
domain = "pad.sbruder.de";
|
|
|
|
protocolUseSSL = true;
|
|
|
|
csp.enable = true;
|
|
|
|
imageUploadType = "filesystem";
|
2022-03-22 18:54:59 +01:00
|
|
|
uploadsPath = "/data/hedgedoc/uploads";
|
2021-03-10 15:40:55 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.hedgedoc = {
|
2021-03-30 16:13:20 +02:00
|
|
|
after = [ "postgresql.service" ];
|
2021-03-10 15:40:55 +01:00
|
|
|
preStart = toString (pkgs.writeShellScript "hedgedoc-generate-session-secret" ''
|
|
|
|
if [ ! -f ${cfg.workDir}/session_secret_env ]; then
|
|
|
|
echo "CMD_SESSION_SECRET=$(${pkgs.pwgen}/bin/pwgen -s 32 1)" > ${cfg.workDir}/session_secret_env
|
|
|
|
fi
|
|
|
|
'');
|
|
|
|
serviceConfig = {
|
|
|
|
Environment = [
|
|
|
|
"CMD_LOGLEVEL=warn"
|
|
|
|
];
|
|
|
|
EnvironmentFile = [
|
|
|
|
"-${cfg.workDir}/session_secret_env" # - ensures that it will not fail on first start
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
2022-03-22 18:54:59 +01:00
|
|
|
"d ${cfg.configuration.uploadsPath} 0700 codimd codimd - -"
|
2021-03-10 15:40:55 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
services.nginx.virtualHosts."pad.sbruder.de" = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
|
|
|
|
locations."/".proxyPass = "http://${cfg.configuration.host}:${toString cfg.configuration.port}";
|
|
|
|
};
|
|
|
|
}
|