]> Git — Sourcephile - sourcephile-nix.git/blob - nixos/modules/services/misc/sourcehut/dispatch.nix
sourcehut: type-check and describe settings
[sourcephile-nix.git] / nixos / modules / services / misc / sourcehut / dispatch.nix
1 { config, lib, pkgs, ... }:
2
3 with lib;
4 let
5 cfg = config.services.sourcehut;
6 cfgIni = cfg.settings;
7 scfg = cfg.dispatch;
8 iniKey = "dispatch.sr.ht";
9
10 drv = pkgs.sourcehut.dispatchsrht;
11 in
12 {
13 options.services.sourcehut.dispatch = {
14 user = mkOption {
15 type = types.str;
16 default = "dispatchsrht";
17 description = ''
18 User for dispatch.sr.ht.
19 '';
20 };
21
22 port = mkOption {
23 type = types.port;
24 default = 5005;
25 description = ''
26 Port on which the "dispatch" module should listen.
27 '';
28 };
29
30 database = mkOption {
31 type = types.str;
32 default = "dispatch.sr.ht";
33 description = ''
34 PostgreSQL database name for dispatch.sr.ht.
35 '';
36 };
37
38 statePath = mkOption {
39 type = types.path;
40 default = "${cfg.statePath}/dispatchsrht";
41 description = ''
42 State path for dispatch.sr.ht.
43 '';
44 };
45 };
46
47 config = with scfg; lib.mkIf (cfg.enable && elem "dispatch" cfg.services) {
48
49 users = {
50 users = {
51 "${user}" = {
52 isSystemUser = true;
53 group = user;
54 description = "dispatch.sr.ht user";
55 };
56 };
57
58 groups = {
59 "${user}" = { };
60 };
61 };
62
63 services.postgresql = {
64 authentication = ''
65 local ${database} ${user} trust
66 '';
67 ensureDatabases = [ database ];
68 ensureUsers = [
69 {
70 name = user;
71 ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
72 }
73 ];
74 };
75
76 systemd = {
77 tmpfiles.rules = [
78 "d ${statePath} 0750 ${user} ${user} -"
79 ];
80
81 services.dispatchsrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
82 after = [ "postgresql.service" "network.target" ];
83 requires = [ "postgresql.service" ];
84 wantedBy = [ "multi-user.target" ];
85
86 description = "dispatch.sr.ht website service";
87
88 serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
89 };
90 };
91
92 services.nginx.virtualHosts."dispatch.${cfg.originBase}" = {
93 forceSSL = true;
94 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
95 locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
96 locations."/static".root = "${pkgs.sourcehut.dispatchsrht}/${pkgs.sourcehut.python.sitePackages}/dispatchsrht";
97 };
98 };
99 }