at 25.11-pre 2.4 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 cfg = config.services.guacamole-server; 9in 10{ 11 options = { 12 services.guacamole-server = { 13 enable = lib.mkEnableOption "Apache Guacamole Server (guacd)"; 14 package = lib.mkPackageOption pkgs "guacamole-server" { }; 15 16 extraEnvironment = lib.mkOption { 17 type = lib.types.attrsOf lib.types.str; 18 default = { }; 19 example = lib.literalExpression '' 20 { 21 ENVIRONMENT = "production"; 22 } 23 ''; 24 description = "Environment variables to pass to guacd."; 25 }; 26 27 host = lib.mkOption { 28 default = "127.0.0.1"; 29 description = '' 30 The host name or IP address the server should listen to. 31 ''; 32 type = lib.types.str; 33 }; 34 35 port = lib.mkOption { 36 default = 4822; 37 description = '' 38 The port the guacd server should listen to. 39 ''; 40 type = lib.types.port; 41 }; 42 43 logbackXml = lib.mkOption { 44 type = lib.types.nullOr lib.types.path; 45 default = null; 46 example = "/path/to/logback.xml"; 47 description = '' 48 Configuration file that correspond to `logback.xml`. 49 ''; 50 }; 51 52 userMappingXml = lib.mkOption { 53 type = lib.types.nullOr lib.types.path; 54 default = null; 55 example = "/path/to/user-mapping.xml"; 56 description = '' 57 Configuration file that correspond to `user-mapping.xml`. 58 ''; 59 }; 60 }; 61 }; 62 63 config = lib.mkIf cfg.enable { 64 # Setup configuration files. 65 environment.etc."guacamole/logback.xml" = lib.mkIf (cfg.logbackXml != null) { 66 source = cfg.logbackXml; 67 }; 68 environment.etc."guacamole/user-mapping.xml" = lib.mkIf (cfg.userMappingXml != null) { 69 source = cfg.userMappingXml; 70 }; 71 72 systemd.services.guacamole-server = { 73 description = "Apache Guacamole server (guacd)"; 74 wantedBy = [ "multi-user.target" ]; 75 after = [ "network.target" ]; 76 environment = { 77 HOME = "/run/guacamole-server"; 78 } // cfg.extraEnvironment; 79 serviceConfig = { 80 ExecStart = "${lib.getExe cfg.package} -f -b ${cfg.host} -l ${toString cfg.port}"; 81 RuntimeDirectory = "guacamole-server"; 82 DynamicUser = true; 83 PrivateTmp = "yes"; 84 Restart = "on-failure"; 85 }; 86 }; 87 }; 88}