blob: e6921b584a10aebd3fa83bfe31812ffafd2de33d (
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
{
lib,
pkgs,
config,
...
}:
let
cfg = config.services.docuseal;
env = {
RAILS_ENV = "production";
NODE_ENV = "production";
WORKDIR = "/var/lib/docuseal";
PORT = toString (cfg.port);
HOST = cfg.host;
REDIS_URL = "redis://${cfg.redis.host}:${toString cfg.redis.port}";
}
// cfg.extraConfig;
in
{
options.services.docuseal = {
enable = lib.mkEnableOption "DocuSeal, open source document signing";
package = lib.mkPackageOption pkgs "docuseal" { };
secretKeyBaseFile = lib.mkOption {
description = ''
Path to file containing the secret key base.
A new secret key base can be generated by running:
`openssl rand -hex 64`
If this file does not exist, it will be created with a new secret key base.
'';
default = "/var/lib/docuseal/secrets/secret-key-base";
type = lib.types.path;
};
host = lib.mkOption {
description = "DocuSeal host.";
type = lib.types.str;
default = "127.0.0.1";
};
port = lib.mkOption {
description = "DocuSeal port.";
type = lib.types.port;
default = 3000;
};
extraConfig = lib.mkOption {
type = lib.types.attrs;
default = { };
description = ''
Extra environment variables to pass to DocuSeal services.
Refer to <https://www.docuseal.com/docs/configuring-docuseal-via-environment-variables>.
'';
};
extraEnvFiles = lib.mkOption {
type = with lib.types; listOf path;
default = [ ];
description = ''
Extra environment files to pass to DocuSeal services. Useful for passing down environmental secrets.
e.g. DATABASE_URL
'';
example = [ "/etc/docuseal/s3config.env" ];
};
redis = {
createLocally = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to create a local redis automatically.";
};
name = lib.mkOption {
type = lib.types.str;
default = "docuseal";
description = ''
Name of the redis server. Only used if `createLocally` is set to true.
'';
};
host = lib.mkOption {
type = lib.types.str;
default = "localhost";
description = ''
Redis server address.
'';
};
port = lib.mkOption {
type = lib.types.port;
default = 6379;
description = "Port of the redis server.";
};
};
};
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.redis.createLocally -> cfg.redis.host == "localhost";
message = "the redis host must be localhost if services.docuseal.redis.createLocally is set to true";
}
];
systemd.services.docuseal = {
description = "DocuSeal server";
wantedBy = [ "multi-user.target" ];
environment = env;
serviceConfig = {
Type = "simple";
ExecStartPre = pkgs.writeShellScript "docuseal-pre-script" ''
cat > /var/lib/docuseal/docuseal.env <<EOF
SECRET_KEY_BASE="$(cat ${cfg.secretKeyBaseFile})"
EOF
'';
ExecStart = "${cfg.package}/bin/rails server --pid=/var/lib/docuseal/docuseal.pids";
Restart = "always";
EnvironmentFile = [ "docuseal.env" ] ++ cfg.extraEnvFiles;
# Runtime directory and mode
RuntimeDirectory = "docuseal";
RuntimeDirectoryMode = "0750";
# System Call Filtering
SystemCallFilter = [
"@system-service"
"~@privileged"
"@chown"
];
# User and group
DynamicUser = true;
# Working directory
WorkingDirectory = "/var/lib/docuseal";
# State directory and mode
StateDirectory = "docuseal";
StateDirectoryMode = "0750";
# Logs directory and mode
LogsDirectory = "docuseal";
LogsDirectoryMode = "0750";
# Proc filesystem
ProcSubset = "pid";
ProtectProc = "invisible";
# Access write directories
UMask = "0027";
# Capabilities
CapabilityBoundingSet = "";
# Security
NoNewPrivileges = true;
# Sandboxing
ProtectSystem = "strict";
ProtectHome = true;
PrivateTmp = true;
PrivateDevices = true;
PrivateUsers = (cfg.port >= 1024);
ProtectClock = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectControlGroups = true;
RestrictAddressFamilies = [
"AF_UNIX"
"AF_INET"
"AF_INET6"
"AF_NETLINK"
];
RestrictNamespaces = true;
LockPersonality = true;
MemoryDenyWriteExecute = false;
RestrictRealtime = true;
RestrictSUIDSGID = true;
RemoveIPC = true;
PrivateMounts = true;
# System Call Filtering
SystemCallArchitectures = "native";
}
// lib.optionalAttrs (cfg.port < 1024) {
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
};
};
services.redis = lib.optionalAttrs cfg.redis.createLocally {
servers."${cfg.redis.name}" = {
enable = true;
port = cfg.redis.port;
};
};
};
meta.maintainers = with lib.maintainers; [ stunkymonkey ];
}
|