summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/web-apps/nostr-rs-relay.nix
blob: 7fb4a59ae89366073168c11ab857fc7e7f739f02 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
{
  config,
  pkgs,
  lib,
  ...
}:
let
  cfg = config.services.nostr-rs-relay;
  settingsFormat = pkgs.formats.toml { };
  configFile = settingsFormat.generate "config.toml" (
    cfg.settings
    // {
      database = {
        data_directory = config.services.nostr-rs-relay.dataDir;
      };
      network = {
        port = config.services.nostr-rs-relay.port;
      };
    }
  );
in
{
  options.services.nostr-rs-relay = {
    enable = lib.mkEnableOption "nostr-rs-relay";

    package = lib.mkPackageOption pkgs "nostr-rs-relay" { };

    port = lib.mkOption {
      default = 12849;
      type = lib.types.port;
      description = "Listen on this port.";
    };

    dataDir = lib.mkOption {
      type = lib.types.path;
      default = "/var/lib/nostr-rs-relay";
      description = "Directory for SQLite files.";
    };

    settings = lib.mkOption {
      inherit (settingsFormat) type;
      default = { };
      description = "See <https://git.sr.ht/~gheartsfield/nostr-rs-relay/#configuration> for documentation.";
    };
  };

  config = lib.mkIf cfg.enable {
    systemd.services.nostr-rs-relay = {
      description = "nostr-rs-relay";
      wants = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];

      serviceConfig = {
        ExecStart = "${cfg.package}/bin/nostr-rs-relay --config ${configFile}";
        DynamicUser = true;
        Restart = "on-failure";
        Type = "simple";

        ReadWritePaths = [ cfg.dataDir ];

        RuntimeDirectory = "nostr-rs-relay";
        StateDirectory = "nostr-rs-relay";

        PrivateTmp = true;
        PrivateUsers = true;
        PrivateDevices = true;
        ProtectSystem = "strict";
        ProtectHome = true;
        NoNewPrivileges = true;
        MemoryDenyWriteExecute = true;
        ProtectKernelTunables = true;
        ProtectKernelModules = true;
        ProtectKernelLogs = true;
        ProtectClock = true;
        ProtectProc = "invisible";
        ProcSubset = "pid";
        ProtectControlGroups = true;
        LockPersonality = true;
        RestrictSUIDSGID = true;
        RemoveIPC = true;
        RestrictRealtime = true;
        ProtectHostname = true;
        CapabilityBoundingSet = "";
        SystemCallFilter = [
          "@system-service"
        ];
        SystemCallArchitectures = "native";
      };
    };
  };

  meta.maintainers = with lib.maintainers; [
    felixzieger
    jb55
  ];
}