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