1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00
Files
niveum/systems/makanek/hedgedoc.nix

105 lines
2.5 KiB
Nix
Raw Permalink Normal View History

2022-03-10 21:52:12 +01:00
{
config,
pkgs,
lib,
2022-03-10 21:52:12 +01:00
...
2025-12-27 22:22:54 +01:00
}:
let
2021-05-30 12:57:37 +02:00
backupLocation = "/var/lib/codimd-backup";
stateLocation = "/var/lib/codimd/state.sqlite";
2021-12-03 12:07:51 +01:00
domain = "pad.kmein.de";
2025-12-27 22:22:54 +01:00
in
{
2021-11-09 22:08:45 +01:00
services.nginx.virtualHosts.${domain} = {
2020-10-31 20:51:25 +01:00
enableACME = true;
2021-11-09 22:08:45 +01:00
forceSSL = true;
locations."/" = {
proxyPass = "https://localhost:3091";
proxyWebsockets = true;
};
};
security.acme.certs.${domain}.group = "hedgecert";
2025-12-27 22:22:54 +01:00
users.groups.hedgecert.members = [
"codimd"
"nginx"
];
2021-11-09 22:08:45 +01:00
security.dhparams = {
enable = true;
2025-12-27 22:22:54 +01:00
params.hedgedoc = { };
2020-10-31 20:51:25 +01:00
};
2021-01-15 10:05:12 +01:00
services.hedgedoc = {
2020-10-31 20:51:25 +01:00
enable = true;
2022-12-01 13:39:16 +01:00
settings = {
2025-12-27 22:22:54 +01:00
allowOrigin = [ domain ];
2021-05-30 10:13:34 +02:00
allowAnonymous = true;
2020-10-31 20:51:25 +01:00
allowGravatar = false;
2021-05-30 10:13:34 +02:00
allowFreeURL = true;
2020-10-31 20:51:25 +01:00
db = {
dialect = "sqlite";
2021-05-30 12:57:37 +02:00
storage = stateLocation;
2020-10-31 20:51:25 +01:00
};
port = 3091;
2021-11-09 22:08:45 +01:00
domain = domain;
useSSL = true;
protocolUseSSL = true;
2025-12-27 22:22:54 +01:00
sslCAPath = [ "/etc/ssl/certs/ca-certificates.crt" ];
2021-11-09 22:08:45 +01:00
sslCertPath = "/var/lib/acme/${domain}/cert.pem";
sslKeyPath = "/var/lib/acme/${domain}/key.pem";
dhParamPath = config.security.dhparams.params.hedgedoc.path;
2020-10-31 20:51:25 +01:00
};
};
2021-05-30 12:57:37 +02:00
2022-05-22 11:47:59 +02:00
niveum.passport.services = [
{
title = "Hedgedoc";
link = "https://${domain}";
description = "lets you collaborate on Markdown documents.";
}
];
2022-04-10 19:38:41 +02:00
systemd.tmpfiles.rules = [
(pkgs.lib.niveum.tmpfilesConfig {
2022-04-10 19:38:41 +02:00
user = "codimd";
group = "codimd";
mode = "0755";
type = "d";
path = backupLocation;
})
];
2021-05-30 12:57:37 +02:00
systemd.services.hedgedoc-backup = {
description = "Hedgedoc backup service";
script = ''
${pkgs.sqlite}/bin/sqlite3 -json ${stateLocation} "select shortid, alias, ownerId, content from Notes" \
2022-03-10 21:52:12 +01:00
| ${
2025-12-27 22:22:54 +01:00
pkgs.writers.writePython3 "hedgedoc-json-to-fs.py" { } ''
2022-03-10 21:52:12 +01:00
import json
import pathlib
import sys
2021-05-30 12:57:37 +02:00
2022-03-10 21:52:12 +01:00
for note in json.load(sys.stdin):
user_directory = pathlib.Path()
if note["ownerId"]:
user_directory = pathlib.Path(note["ownerId"])
user_directory.mkdir(exist_ok=True)
file_path = user_directory / (
(note["alias"] if note["alias"] else note["shortid"]) + ".md"
)
file_path.write_text(note["content"])
print(f" {file_path}", file=sys.stderr)
''
}
2021-05-30 12:57:37 +02:00
'';
startAt = "hourly";
serviceConfig = {
Type = "oneshot";
User = "codimd";
Group = "codimd";
WorkingDirectory = backupLocation;
};
};
2020-10-31 20:51:25 +01:00
}