]> Git — Sourcephile - sourcephile-nix.git/blob - nixos/modules/services/misc/sourcehut/paste.nix
losurdo: sourcehut: sync config with module changes
[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 statePath = "/var/lib/sourcehut/pastesrht";
10
11 rcfg = config.services.redis;
12 drv = pkgs.sourcehut.pastesrht;
13 in
14 {
15 options.services.sourcehut.paste = {
16 enable = mkEnableOption "paste service";
17
18 user = mkOption {
19 type = types.str;
20 default = "pastesrht";
21 description = ''
22 User for paste.sr.ht.
23 '';
24 };
25
26 port = mkOption {
27 type = types.port;
28 default = 5011;
29 description = ''
30 Port on which the "paste" module should listen.
31 '';
32 };
33
34 database = mkOption {
35 type = types.str;
36 default = "paste.sr.ht";
37 description = ''
38 PostgreSQL database name for paste.sr.ht.
39 '';
40 };
41 };
42
43 config = with scfg; lib.mkIf (cfg.enable && scfg.enable) {
44 users = {
45 users = {
46 "${user}" = {
47 isSystemUser = true;
48 group = user;
49 description = "paste.sr.ht user";
50 };
51 };
52
53 groups = {
54 "${user}" = { };
55 };
56 };
57
58 services.postgresql = {
59 authentication = ''
60 local ${database} ${user} trust
61 '';
62 ensureDatabases = [ database ];
63 ensureUsers = [
64 {
65 name = user;
66 ensurePermissions = { "DATABASE \"${database}\"" = "ALL PRIVILEGES"; };
67 }
68 ];
69 };
70
71 systemd = {
72 services = {
73 pastesrht = import ./service.nix { inherit config pkgs lib; initDB = true; } scfg drv iniKey {
74 after = [ "postgresql.service" "network.target" ];
75 requires = [ "postgresql.service" ];
76 wantedBy = [ "multi-user.target" ];
77
78 description = "paste.sr.ht website service";
79
80 serviceConfig.ExecStart = "${cfg.python}/bin/gunicorn ${drv.pname}.app:app -b ${cfg.address}:${toString port}";
81 };
82
83 pastesrht-webhooks = {
84 after = [ "postgresql.service" "network.target" ];
85 requires = [ "postgresql.service" ];
86 wantedBy = [ "multi-user.target" ];
87
88 description = "paste.sr.ht webhooks service";
89 serviceConfig = {
90 Type = "simple";
91 User = user;
92 Restart = "always";
93 ExecStart = "${cfg.python}/bin/celery -A ${drv.pname}.webhooks worker --loglevel INFO --pool eventlet";
94 };
95
96 };
97 };
98 };
99
100 services.sourcehut.settings = {
101 };
102
103 services.nginx.virtualHosts."paste.${cfg.originBase}" = {
104 forceSSL = true;
105 locations."/".proxyPass = "http://${cfg.address}:${toString port}";
106 locations."/query".proxyPass = cfgIni."meta.sr.ht".api-origin;
107 locations."/static".root = "${pkgs.sourcehut.pastesrht}/${pkgs.sourcehut.python.sitePackages}/pastesrht";
108 };
109 };
110 }