1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.plantuml-server;
8
9in
10
11{
12 options = {
13 services.plantuml-server = {
14 enable = mkEnableOption "PlantUML server";
15
16 package = mkOption {
17 type = types.package;
18 default = pkgs.plantuml-server;
19 description = "PlantUML server package to use";
20 };
21
22 user = mkOption {
23 type = types.str;
24 default = "plantuml";
25 description = "User which runs PlantUML server.";
26 };
27
28 group = mkOption {
29 type = types.str;
30 default = "plantuml";
31 description = "Group which runs PlantUML server.";
32 };
33
34 home = mkOption {
35 type = types.str;
36 default = "/var/lib/plantuml";
37 description = "Home directory of the PlantUML server instance.";
38 };
39
40 listenHost = mkOption {
41 type = types.str;
42 default = "127.0.0.1";
43 description = "Host to listen on.";
44 };
45
46 listenPort = mkOption {
47 type = types.int;
48 default = 8080;
49 description = "Port to listen on.";
50 };
51
52 plantumlLimitSize = mkOption {
53 type = types.int;
54 default = 4096;
55 description = "Limits image width and height.";
56 };
57
58 graphvizPackage = mkOption {
59 type = types.package;
60 default = pkgs.graphviz_2_32;
61 description = "Package containing the dot executable.";
62 };
63
64 plantumlStats = mkOption {
65 type = types.bool;
66 default = false;
67 description = "Set it to on to enable statistics report (https://plantuml.com/statistics-report).";
68 };
69
70 httpAuthorization = mkOption {
71 type = types.nullOr types.str;
72 default = null;
73 description = "When calling the proxy endpoint, the value of HTTP_AUTHORIZATION will be used to set the HTTP Authorization header.";
74 };
75
76 allowPlantumlInclude = mkOption {
77 type = types.bool;
78 default = false;
79 description = "Enables !include processing which can read files from the server into diagrams. Files are read relative to the current working directory.";
80 };
81 };
82 };
83
84 config = mkIf cfg.enable {
85 users.users.${cfg.user} = {
86 isSystemUser = true;
87 group = cfg.group;
88 home = cfg.home;
89 createHome = true;
90 };
91
92 users.groups.${cfg.group} = {};
93
94 systemd.services.plantuml-server = {
95 description = "PlantUML server";
96 wantedBy = [ "multi-user.target" ];
97 path = [ cfg.home ];
98 environment = {
99 PLANTUML_LIMIT_SIZE = builtins.toString cfg.plantumlLimitSize;
100 GRAPHVIZ_DOT = "${cfg.graphvizPackage}/bin/dot";
101 PLANTUML_STATS = if cfg.plantumlStats then "on" else "off";
102 HTTP_AUTHORIZATION = cfg.httpAuthorization;
103 ALLOW_PLANTUML_INCLUDE = if cfg.allowPlantumlInclude then "true" else "false";
104 };
105 script = ''
106 ${pkgs.jre}/bin/java \
107 -jar ${pkgs.jetty}/start.jar \
108 --module=deploy,http,jsp \
109 jetty.home=${pkgs.jetty} \
110 jetty.base=${cfg.package} \
111 jetty.http.host=${cfg.listenHost} \
112 jetty.http.port=${builtins.toString cfg.listenPort}
113 '';
114 serviceConfig = {
115 User = cfg.user;
116 Group = cfg.group;
117 PrivateTmp = true;
118 };
119 };
120 };
121
122 meta.maintainers = with lib.maintainers; [ truh ];
123}