2024-01-06 01:19:35 +01:00
|
|
|
# SPDX-FileCopyrightText: 2021-2023 Simon Bruder <simon@sbruder.de>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
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-23 17:27:55 +01:00
|
|
|
name = "hedgedoc";
|
2023-12-02 18:54:23 +01:00
|
|
|
ensureDBOwnership = true;
|
2021-03-10 15:40:55 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.hedgedoc = {
|
|
|
|
enable = true;
|
2022-12-10 15:15:58 +01:00
|
|
|
settings = {
|
2021-03-10 15:40:55 +01:00
|
|
|
host = "127.0.0.1";
|
|
|
|
port = 3001;
|
|
|
|
db = {
|
|
|
|
dialect = "postgres";
|
|
|
|
host = "/run/postgresql";
|
2022-03-23 17:27:55 +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";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
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" ''
|
2023-12-02 18:54:23 +01:00
|
|
|
if [ ! -f /var/lib/hedgedoc/session_secret_env ]; then
|
|
|
|
echo "CMD_SESSION_SECRET=$(${pkgs.pwgen}/bin/pwgen -s 32 1)" > /var/lib/hedgedoc/session_secret_env
|
2021-03-10 15:40:55 +01:00
|
|
|
fi
|
|
|
|
'');
|
|
|
|
serviceConfig = {
|
|
|
|
Environment = [
|
|
|
|
"CMD_LOGLEVEL=warn"
|
|
|
|
];
|
|
|
|
EnvironmentFile = [
|
2023-12-02 18:54:23 +01:00
|
|
|
"-/var/lib/hedgedoc/session_secret_env" # - ensures that it will not fail on first start
|
2021-03-10 15:40:55 +01:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
2022-12-10 15:15:58 +01:00
|
|
|
"d ${cfg.settings.uploadsPath} 0700 hedgedoc hedgedoc - -"
|
2021-03-10 15:40:55 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
services.nginx.virtualHosts."pad.sbruder.de" = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
|
2022-12-10 15:15:58 +01:00
|
|
|
locations."/".proxyPass = "http://${cfg.settings.host}:${toString cfg.settings.port}";
|
2021-03-10 15:40:55 +01:00
|
|
|
};
|
|
|
|
}
|