summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/web-apps/guacamole-server.nix
blob: 2c20247ec3d905a5408578620c1a58b842f045fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.services.guacamole-server;
in
{
  imports = [
    (lib.mkRenamedOptionModule
      [ "services" "guacamole-server" "logbackXml" ]
      [ "services" "guacamole-client" "logbackXml" ]
    )
    (lib.mkRenamedOptionModule
      [ "services" "guacamole-server" "userMappingXml" ]
      [ "services" "guacamole-client" "userMappingXml" ]
    )
  ];
  options = {
    services.guacamole-server = {
      enable = lib.mkEnableOption "Apache Guacamole Server (guacd)";
      package = lib.mkPackageOption pkgs "guacamole-server" { };

      extraEnvironment = lib.mkOption {
        type = lib.types.attrsOf lib.types.str;
        default = { };
        example = lib.literalExpression ''
          {
            ENVIRONMENT = "production";
          }
        '';
        description = "Environment variables to pass to guacd.";
      };

      host = lib.mkOption {
        default = "127.0.0.1";
        description = ''
          The host name or IP address the server should listen to.
        '';
        type = lib.types.str;
      };

      port = lib.mkOption {
        default = 4822;
        description = ''
          The port the guacd server should listen to.
        '';
        type = lib.types.port;
      };
    };
  };

  config = lib.mkIf cfg.enable {
    systemd.services.guacamole-server = {
      description = "Apache Guacamole server (guacd)";
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" ];
      environment = {
        HOME = "/run/guacamole-server";
      }
      // cfg.extraEnvironment;
      serviceConfig = {
        ExecStart = "${lib.getExe cfg.package} -f -b ${cfg.host} -l ${toString cfg.port}";
        RuntimeDirectory = "guacamole-server";
        DynamicUser = true;
        PrivateTmp = "yes";
        Restart = "on-failure";
      };
    };
  };
}