about summary refs log tree commit diff
path: root/modules/services
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2020-05-02 15:28:25 +0200
committerProfpatsch <mail@profpatsch.de>2020-05-02 15:30:05 +0200
commitaec8006f606b68a9d2b50da21f3d9e9353d03295 (patch)
treedfa8edfa47561bdc7c2c54bc6db47947ba0d2c54 /modules/services
parent71860c9595cdac4398288a59e14b0d4249d11f3a (diff)
modules: add services/drawpile
Headless server for the drawpile shared drawing application.
Diffstat (limited to 'modules/services')
-rw-r--r--modules/services/drawpile.nix71
1 files changed, 71 insertions, 0 deletions
diff --git a/modules/services/drawpile.nix b/modules/services/drawpile.nix
new file mode 100644
index 00000000..55a5ba69
--- /dev/null
+++ b/modules/services/drawpile.nix
@@ -0,0 +1,71 @@
+{ pkgs, lib, config, ... }:
+
+let
+  cfg = config.vuizvui.services.drawpile;
+
+  port = 27750;
+  adminPort = 9876;
+  stateDir = "/var/lib/drawpile";
+
+in {
+
+  options = {
+
+    vuizvui.services.drawpile = {
+      enable = lib.mkEnableOption "drawpile dedicated server";
+
+      configFile = lib.mkOption {
+        type = lib.types.str;
+        description = ''
+          The ini configuration file of the server.
+          See https://drawpile.net/help/server/
+        '';
+      };
+
+    };
+  };
+
+
+  config = lib.mkIf cfg.enable {
+    systemd.services.drawpile = {
+      description   = "drawpile headless server";
+      wantedBy      = [ "multi-user.target" ];
+      after         = [ "network.target" ];
+
+      serviceConfig = {
+        Restart = "always";
+        RestartSec = "1s";
+        KillSignal = "SIGINT";
+        DynamicUser = true;
+        StateDirectory = "drawpile";
+        UMask = "0007";
+        ExecStart = toString [
+          "${pkgs.drawpile-server-headless}/bin/drawpile-srv"
+          "--config" (pkgs.writeText "drawpile-server.ini" cfg.configFile)
+          # implicit from StateDirectory
+          "--sessions" "/var/lib/drawpile"
+          "--port" (toString port)
+          "--web-admin-port" (toString adminPort)
+        ];
+
+        # Sandboxing
+        NoNewPrivileges = true;
+        PrivateTmp = true;
+        PrivateDevices = true;
+        ProtectSystem = "strict";
+        ProtectHome = true;
+        ProtectControlGroups = true;
+        ProtectKernelModules = true;
+        ProtectKernelTunables = true;
+        RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" "AF_NETLINK" ];
+        RestrictRealtime = true;
+        RestrictNamespaces = true;
+        MemoryDenyWriteExecute = true;
+      };
+    };
+
+    networking.firewall.allowedUDPPorts = [ port ];
+
+  };
+
+}