about summary refs log tree commit diff
path: root/modules/nixos/hydra.nix
blob: 590fecb1e544222dacabe809b1404f7ad086942f (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
{
  config,
  lib,
  ...
}:
with lib; let
  cfg = config.nixfiles.modules.hydra;
in {
  options.nixfiles.modules.hydra = {
    enable = mkEnableOption "Hydra";

    domain = mkOption {
      description = "Domain name sans protocol scheme.";
      type = with types; str;
      default = "hydra.${config.networking.domain}";
    };

    port = mkOption {
      description = "Port.";
      type = with types; port;
      default = 7754;
    };
  };

  config = mkIf cfg.enable {
    nixfiles.modules = {
      nginx = {
        enable = true;
        upstreams.hydra.servers."127.0.0.1:${toString cfg.port}" = {};
        virtualHosts.${cfg.domain}.locations."/".proxyPass = "http://hydra";
      };
      postgresql.enable = true;
    };

    services = let
      db = "hydra";
    in {
      hydra = {
        enable = true;
        listenHost = "127.0.0.1";
        inherit (cfg) port;
        dbi = "dbi:Pg:dbname=${db};user=${db}";
        hydraURL = cfg.domain;
      };

      postgresql = {
        ensureDatabases = [db];
        ensureUsers = [
          {
            name = db;
            ensurePermissions."DATABASE \"${db}\"" = "ALL";
          }
        ];
      };
    };
  };
}

Consider giving Nix/NixOS a try! <3