2023-04-22 16:49:04 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.services.hedgedoc.settings;
|
|
|
|
domain = "md.feal.no";
|
2023-04-26 23:40:18 +02:00
|
|
|
port = 3300;
|
2023-04-22 16:49:04 +02:00
|
|
|
host = "0.0.0.0";
|
2023-10-06 00:19:04 +02:00
|
|
|
authServerUrl = "https://auth.feal.no";
|
2023-04-22 16:49:04 +02:00
|
|
|
in {
|
2023-04-26 12:07:36 +02:00
|
|
|
# Contains CMD_SESSION_SECRET and CMD_OAUTH2_CLIENT_SECRET
|
|
|
|
sops.secrets."hedgedoc/env" = {
|
|
|
|
restartUnits = [ "hedgedoc.service" ];
|
|
|
|
};
|
|
|
|
|
2023-04-22 16:49:04 +02:00
|
|
|
services.hedgedoc = {
|
|
|
|
enable = true;
|
2023-04-26 23:40:18 +02:00
|
|
|
environmentFile = config.sops.secrets."hedgedoc/env".path;
|
2023-04-22 16:49:04 +02:00
|
|
|
settings = {
|
|
|
|
inherit domain port host;
|
|
|
|
protocolUseSSL = true;
|
2023-04-26 23:40:18 +02:00
|
|
|
sessionSecret = "$CMD_SESSION_SECRET";
|
|
|
|
|
|
|
|
allowFreeURL = true;
|
2023-05-03 17:49:50 +02:00
|
|
|
allowAnonymous = false;
|
|
|
|
allowAnonymousEdits = true; # Allow anonymous edits with the "freely" permission
|
|
|
|
|
|
|
|
dbURL = "postgres://hedgedoc:@localhost/hedgedoc";
|
2023-04-26 12:07:36 +02:00
|
|
|
|
2023-04-22 16:49:04 +02:00
|
|
|
email = false;
|
2023-04-26 23:40:18 +02:00
|
|
|
oauth2 = {
|
2023-04-22 16:49:04 +02:00
|
|
|
baseURL = "${authServerUrl}/oauth2";
|
|
|
|
tokenURL = "${authServerUrl}/oauth2/token";
|
|
|
|
authorizationURL = "${authServerUrl}/ui/oauth2";
|
|
|
|
userProfileURL = "${authServerUrl}/oauth2/openid/hedgedoc/userinfo";
|
|
|
|
|
|
|
|
clientID = "hedgedoc";
|
2023-04-26 23:40:18 +02:00
|
|
|
clientSecret = "$CMD_OAUTH2_CLIENT_SECRET";
|
2023-04-22 16:49:04 +02:00
|
|
|
scope = "openid email profile";
|
|
|
|
userProfileUsernameAttr = "name";
|
|
|
|
userProfileEmailAttr = "email";
|
|
|
|
userProfileDisplayNameAttr = "displayname";
|
|
|
|
|
|
|
|
providerName = "KaniDM";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
2023-04-26 23:40:18 +02:00
|
|
|
|
2023-06-07 20:23:49 +02:00
|
|
|
systemd.services.hedgedoc = {
|
|
|
|
requires = [
|
|
|
|
"postgresql.service"
|
2023-10-06 00:19:04 +02:00
|
|
|
# "kanidm.service"
|
2023-06-07 20:23:49 +02:00
|
|
|
];
|
|
|
|
serviceConfig = let
|
|
|
|
workDir = "/var/lib/hedgedoc";
|
|
|
|
in {
|
|
|
|
WorkingDirectory = lib.mkForce workDir;
|
|
|
|
StateDirectory = lib.mkForce [ "hedgedoc" "hedgedoc/uploads" ];
|
|
|
|
|
|
|
|
# Better safe than sorry :)
|
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
LockPersonality = true;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateMounts = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
ReadWritePaths = [ workDir ];
|
|
|
|
RemoveIPC = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
UMask = "0007";
|
|
|
|
RestrictAddressFamilies = [ "AF_UNIX AF_INET AF_INET6" ];
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = "~@clock @cpu-emulation @debug @keyring @module @mount @obsolete @raw-io @reboot @setuid @swap";
|
|
|
|
};
|
2023-04-22 16:49:04 +02:00
|
|
|
};
|
2023-04-26 23:40:18 +02:00
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [ port ];
|
2023-05-03 17:49:50 +02:00
|
|
|
|
|
|
|
services.postgresql = {
|
|
|
|
ensureDatabases = [ "hedgedoc" ];
|
|
|
|
ensureUsers = [{
|
|
|
|
name = "hedgedoc";
|
|
|
|
ensurePermissions = {
|
|
|
|
"DATABASE \"hedgedoc\"" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
}];
|
|
|
|
};
|
2023-04-22 16:49:04 +02:00
|
|
|
}
|