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