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

66 lines
1.8 KiB
Nix
Raw Normal View History

2021-05-30 12:57:37 +02:00
{ pkgs, ... }:
let
backupLocation = "/var/lib/codimd-backup";
stateLocation = "/var/lib/codimd/state.sqlite";
nixpkgs-unstable = import <nixpkgs-unstable> {};
2021-05-30 12:57:37 +02:00
in
2020-10-31 20:51:25 +01:00
{
2021-05-30 12:57:37 +02:00
imports = [ <stockholm/krebs/3modules/permown.nix> ];
2020-10-31 20:51:25 +01:00
services.nginx.virtualHosts."pad.xn--kiern-0qa.de" = {
enableACME = true;
addSSL = true;
locations."/".extraConfig = ''
client_max_body_size 4G;
proxy_set_header Host $host;
proxy_pass http://localhost:3091;
'';
};
2021-01-15 10:05:12 +01:00
services.hedgedoc = {
2020-10-31 20:51:25 +01:00
enable = true;
configuration = {
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-05-30 12:57:37 +02:00
krebs.permown.${backupLocation} = { owner = "codimd"; group = "codimd"; umask = "0002"; };
systemd.services.hedgedoc-backup = {
description = "Hedgedoc backup service";
script = ''
${nixpkgs-unstable.sqlite}/bin/sqlite3 -json ${stateLocation} "select shortid, alias, ownerId, content from Notes" \
| ${pkgs.writers.writePython3 "hedgedoc-json-to-fs.py" {} ''
import json
2021-05-30 12:57:37 +02:00
import pathlib
import sys
for note in json.load(sys.stdin):
user_directory = pathlib.Path()
if note["ownerId"]:
user_directory = pathlib.Path(note["ownerId"])
2021-05-30 12:57:37 +02:00
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
}