Skip to content

Commit 2b19582

Browse files
authored
Add NixOS module for payjoin-mailroom (#1366)
2 parents 55fbc08 + adcbab0 commit 2b19582

2 files changed

Lines changed: 120 additions & 1 deletion

File tree

flake.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
treefmt-nix,
3131
nix2container,
3232
}:
33-
flake-utils.lib.eachDefaultSystem (
33+
{
34+
nixosModules.payjoin-mailroom = import ./nix/modules/payjoin-mailroom.nix self;
35+
}
36+
// flake-utils.lib.eachDefaultSystem (
3437
system:
3538
let
3639
pkgs = import nixpkgs {

nix/modules/payjoin-mailroom.nix

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
flake:
2+
{
3+
config,
4+
lib,
5+
pkgs,
6+
...
7+
}:
8+
let
9+
cfg = config.services.payjoin-mailroom;
10+
settingsFormat = pkgs.formats.toml { };
11+
configFile = settingsFormat.generate "payjoin-mailroom.toml" cfg.settings;
12+
in
13+
{
14+
options.services.payjoin-mailroom = {
15+
enable = lib.mkEnableOption "payjoin-mailroom, a combined payjoin directory and OHTTP relay";
16+
17+
package = lib.mkOption {
18+
type = lib.types.package;
19+
default = flake.packages.${pkgs.system}.payjoin-mailroom;
20+
defaultText = lib.literalExpression "flake.packages.\${pkgs.system}.payjoin-mailroom";
21+
description = "The payjoin-mailroom package to use.";
22+
};
23+
24+
settings = lib.mkOption {
25+
type = settingsFormat.type;
26+
default = { };
27+
description = ''
28+
Configuration for payjoin-mailroom, serialized to TOML.
29+
See config.example.toml for available options.
30+
'';
31+
example = lib.literalExpression ''
32+
{
33+
listener = "[::]:443";
34+
timeout = 30;
35+
acme = {
36+
domains = [ "payjo.in" ];
37+
contact = [ "mailto:admin@payjo.in" ];
38+
};
39+
}
40+
'';
41+
};
42+
43+
environment = lib.mkOption {
44+
type = lib.types.attrsOf lib.types.str;
45+
default = { };
46+
description = "Additional environment variables to pass to the service.";
47+
example = {
48+
RUST_LOG = "debug";
49+
};
50+
};
51+
52+
environmentFile = lib.mkOption {
53+
type = lib.types.nullOr lib.types.path;
54+
default = null;
55+
description = ''
56+
File containing environment variables for the service.
57+
Useful for secrets like PJ_TELEMETRY__AUTH_TOKEN.
58+
'';
59+
};
60+
};
61+
62+
config = lib.mkIf cfg.enable {
63+
services.payjoin-mailroom.settings = {
64+
storage_dir = lib.mkDefault "/var/lib/payjoin-mailroom";
65+
};
66+
67+
systemd.services.payjoin-mailroom = {
68+
description = "Payjoin Mailroom";
69+
wantedBy = [ "multi-user.target" ];
70+
after = [ "network-online.target" ];
71+
wants = [ "network-online.target" ];
72+
73+
environment = {
74+
RUST_LOG = lib.mkDefault "info";
75+
}
76+
// cfg.environment;
77+
78+
serviceConfig = {
79+
ExecStart = "${cfg.package}/bin/payjoin-mailroom --config ${configFile}";
80+
DynamicUser = true;
81+
StateDirectory = "payjoin-mailroom";
82+
WorkingDirectory = "/var/lib/payjoin-mailroom";
83+
Restart = "on-failure";
84+
RestartSec = 5;
85+
86+
# Allow binding to privileged ports (e.g. 443 for ACME)
87+
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
88+
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
89+
LockPersonality = true;
90+
MemoryDenyWriteExecute = true;
91+
NoNewPrivileges = true;
92+
PrivateDevices = true;
93+
PrivateTmp = true;
94+
ProtectClock = true;
95+
ProtectControlGroups = true;
96+
ProtectHome = true;
97+
ProtectHostname = true;
98+
ProtectKernelLogs = true;
99+
ProtectKernelModules = true;
100+
ProtectKernelTunables = true;
101+
ProtectSystem = "strict";
102+
RestrictAddressFamilies = [
103+
"AF_INET"
104+
"AF_INET6"
105+
"AF_UNIX"
106+
];
107+
RestrictNamespaces = true;
108+
RestrictRealtime = true;
109+
SystemCallArchitectures = "native";
110+
}
111+
// lib.optionalAttrs (cfg.environmentFile != null) {
112+
EnvironmentFile = cfg.environmentFile;
113+
};
114+
};
115+
};
116+
}

0 commit comments

Comments
 (0)