]> Git — Sourcephile - sourcephile-nix.git/blob - nixos/modules/services/misc/sourcehut/paste.nix
sourcehut: type-check and describe settings
[sourcephile-nix.git] / nixos / modules / services / misc / sourcehut / paste.nix
1 { config, lib, pkgs, ... }:
2
3 with lib;
4 let
5 cfg = config.services.sourcehut;
6 cfgIni = cfg.settings;
7 scfg = cfg.paste;
8 iniKey = "paste.sr.ht";
9
10 rcfg = config.services.redis;
11 drv = pkgs.sourcehut.pastesrht;
12 in
13 {
14 options.services.sourcehut.paste = {
15 user = mkOption {
16 type = types.str;
17 default = "pastesrht";
18 description = ''
19 User for paste.sr.ht.
20 '';
21 };
22
23 port = mkOption {
24 type = types.port;
25 default = 5011;
26 description = ''
27 Port on which the "paste" module should listen.
28 '';
29 };
30
31 database = mkOption {
32 type = types.str;
33 default = "paste.sr.ht";
34 description = ''
35 PostgreSQL database name for paste.sr.ht.
36 '';
37 };
38
39 statePath = mkOption {
40 type = types.path;
41 default = "${cfg.statePath}/pastesrht";
42 description = ''
43 State path for pastesrht.sr.ht.
44 '';
45 };
46 };
47
48 config = with scfg; lib.mkIf (cfg.enable && elem "paste" cfg.services) {
49 users = {
50 users = {
51 "${user}" = {
52 isSystemUser = true;
53 group = user;
54 description = "paste.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 = {
82 pastesrht = import ./service.nix { inherit config pkgs lib; } scfg drv iniKey {
83 after = [ "postgresql.service" "network.target" ];
84 requires = [ "postgresql.service" ];
85 wantedBy = [ "multi-user.target" ];
86
87 description = "paste.sr.ht website service";
88
89 serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
90 };
91
92 pastesrht-webhooks = {
93 after = [ "postgresql.service" "network.target" ];
94 requires = [ "postgresql.service" ];
95 wantedBy = [ "multi-user.target" ];
96
97 description = "paste.sr.ht webhooks service";
98 serviceConfig = {
99 Type = "simple";
100 User = user;
101 Restart = "always";
102 ExecStart = "${cfg.python}/bin/celery -A ${drv.pname}.webhooks worker --loglevel INFO --pool eventlet";
103 };
104
105 };
106 };
107 };
108
109 services.sourcehut.settings = {
110 };
111
112 services.nginx.virtualHosts."paste.${cfg.originBase}" = {
113 forceSSL = true;
114 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
115 locations."/query".proxyPass = "http://${cfg.address}:${toString (port + 100)}";
116 locations."/static".root = "${pkgs.sourcehut.pastesrht}/${pkgs.sourcehut.python.sitePackages}/pastesrht";
117 };
118 };
119 }