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
58
59
60
61
62
63
64
65
{ depot, pkgs, lib, config, ... }:

let
  cfg = config.profpatsch.modularPlakate;
  modular-flyer = depot.users.Profpatsch.modular-flyer;
in {
  options.profpatsch.modularPlakate = {
    enable = lib.mkEnableOption "modular-plakate flyer distribution map";

    port = lib.mkOption {
      type = lib.types.port;
      default = 8766;
      description = "Port for the modular-flyer service";
    };

    baseUrl = lib.mkOption {
      type = lib.types.str;
      default = "https://modular-plakate.softwaregardening.org";
      description = "Public base URL used for invite links";
    };

    dbPath = lib.mkOption {
      type = lib.types.str;
      default = "/var/lib/modular-plakate/modular-flyer.db";
      description = "Path to the SQLite database";
    };
  };

  config = lib.mkIf cfg.enable {

    systemd.services.modular-plakate = {
      description = "Modular Plakate — festival flyer distribution map";
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" ];
      serviceConfig = {
        ExecStart = lib.escapeShellArgs [
          "${modular-flyer}/bin/modular-flyer"
          "serve"
          "--addr" ":${toString cfg.port}"
          "--base-url" cfg.baseUrl
          cfg.dbPath
        ];
        StateDirectory = "modular-plakate";
        Restart = "on-failure";
        RestartSec = 5;
        DynamicUser = true;
      };
    };

    services.nginx.virtualHosts."modular-plakate.softwaregardening.org" = {
      forceSSL = true;
      enableACME = true;
      locations."/" = {
        proxyPass = "http://127.0.0.1:${toString cfg.port}";
        extraConfig = ''
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
        '';
      };
    };

  };
}