-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.nix
149 lines (130 loc) · 3.67 KB
/
default.nix
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
{
config,
lib,
pkgs,
...
}:
with lib;
let
cfg = config.services.msgscript;
pluginDir = pkgs.symlinkJoin {
name = "msgscript-server-plugins";
paths = cfg.plugins;
};
in
{
options.services.msgscript = {
enable = mkEnableOption "Enable the msgscript service";
etcdEndpoints = mkOption {
type = types.listOf types.str;
default = [ "http://127.0.0.1:2379" ];
description = mdDoc "Etcd endpoints to connect to";
};
backend = mkOption {
type = types.enum [
"etcd"
"file"
];
default = "file";
description = "Backend to use to store/execute the functions from";
};
plugins = mkOption {
type = types.listOf types.package;
default = [ ];
description = "Plugins to add to the server";
};
natsUrl = mkOption {
type = types.str;
default = "";
description = mdDoc "Nats.io URL to connect to";
};
dataDir = mkOption {
type = types.str;
default = "/var/lib/msgscript";
description = mdDoc "Directory available to msgscript-server for io operation. The server owns this directory";
};
scriptDir = mkOption {
type = types.str;
default = "${cfg.dataDir}/scripts";
};
libraryDir = mkOption {
type = types.str;
default = "${cfg.dataDir}/libs";
};
user = mkOption {
type = types.str;
default = "msgscript";
description = "User account under which msgscript runs.";
};
group = mkOption {
type = types.str;
default = "msgscript";
description = "Group under which msgscript runs.";
};
};
config = mkIf cfg.enable {
systemd.services.msgscript = {
description = "Run Lua function from nats subjects";
restartIfChanged = true;
serviceConfig = {
ExecStart = "${pkgs.msgscript-server}/bin/msgscript -backend ${cfg.backend} -etcdurl ${lib.concatStringsSep "," cfg.etcdEndpoints} -natsurl ${cfg.natsUrl} -plugin ${pluginDir} -script ${cfg.scriptDir} -library ${cfg.libraryDir}";
User = cfg.user;
Group = cfg.group;
WorkingDirectory = cfg.dataDir;
RuntimeDirectory = cfg.dataDir;
Restart = "on-failure";
TimeoutSec = 15;
# Security options:
NoNewPrivileges = true;
SystemCallArchitectures = "native";
RestrictAddressFamilies = [
"AF_INET"
"AF_INET6"
];
RestrictNamespaces = !config.boot.isContainer;
RestrictRealtime = true;
RestrictSUIDSGID = true;
ProtectControlGroups = !config.boot.isContainer;
ProtectHostname = true;
ProtectKernelLogs = !config.boot.isContainer;
ProtectKernelModules = !config.boot.isContainer;
ProtectKernelTunables = !config.boot.isContainer;
LockPersonality = true;
PrivateTmp = !config.boot.isContainer;
PrivateDevices = true;
PrivateUsers = true;
RemoveIPC = true;
SystemCallFilter = [
"~@clock"
"~@aio"
"~@chown"
"~@cpu-emulation"
"~@debug"
"~@keyring"
"~@memlock"
"~@module"
"~@mount"
"~@obsolete"
"~@privileged"
"~@raw-io"
"~@reboot"
"~@setuid"
"~@swap"
];
SystemCallErrorNumber = "EPERM";
};
wantedBy = [ "multi-user.target" ];
after = [ "networking.target" ];
};
users.users = mkIf (cfg.user == "msgscript") {
msgscript = {
inherit (cfg) group;
isSystemUser = true;
home = cfg.dataDir;
};
};
users.groups = mkIf (cfg.group == "msgscript") {
msgscript = { };
};
};
}