summary refs log tree commit diff
path: root/nixos/modules/services/web-apps/trac.nix
blob: 207fb857438a4f70f12d37bf3d52681f839c5221 (plain) (blame)
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
74
75
76
77
78
79
{ config, lib, pkgs, ... }:

let
  cfg = config.services.trac;

  inherit (lib) mkEnableOption mkIf mkOption types;

in {

  options = {

    services.trac = {
      enable = mkEnableOption "Trac service";

      listen = {
        ip = mkOption {
          type = types.str;
          default = "0.0.0.0";
          description = ''
            IP address that Trac should listen on.
          '';
        };

        port = mkOption {
          type = types.port;
          default = 8000;
          description = ''
            Listen port for Trac.
          '';
        };
      };

      dataDir = mkOption {
        default = "/var/lib/trac";
        type = types.path;
        description = ''
            The directory for storing the Trac data.
        '';
      };

      openFirewall = mkOption {
        type = types.bool;
        default = false;
        description = ''
          Open ports in the firewall for Trac.
        '';
      };
    };

  };

  config = mkIf cfg.enable {

    systemd.services.trac = {
      description = "Trac server";
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        DynamicUser = true;
        StateDirectory = baseNameOf cfg.dataDir;
        ExecStart = ''
          ${pkgs.trac}/bin/tracd -s \
            -b ${toString cfg.listen.ip} \
            -p ${toString cfg.listen.port} \
            ${cfg.dataDir}
        '';
      };
      preStart = ''
        if [ ! -e ${cfg.dataDir}/VERSION ]; then
          ${pkgs.trac}/bin/trac-admin ${cfg.dataDir} initenv Trac "sqlite:db/trac.db"
        fi
      '';
    };

    networking.firewall = mkIf cfg.openFirewall {
      allowedTCPPorts = [ cfg.listen.port ];
    };

  };
}