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
|
{ config, lib, pkgs, ... }:
let
cfg = config.services.surrealdb;
in {
options = {
services.surrealdb = {
enable = lib.mkEnableOption "SurrealDB, a scalable, distributed, collaborative, document-graph database, for the realtime web";
package = lib.mkPackageOption pkgs "surrealdb" { };
dbPath = lib.mkOption {
type = lib.types.str;
description = ''
The path that surrealdb will write data to. Use null for in-memory.
Can be one of "memory", "rocksdb://:path", "surrealkv://:path", "tikv://:addr", "fdb://:addr".
'';
default = "rocksdb:///var/lib/surrealdb/";
example = "memory";
};
host = lib.mkOption {
type = lib.types.str;
description = ''
The host that surrealdb will connect to.
'';
default = "127.0.0.1";
example = "127.0.0.1";
};
port = lib.mkOption {
type = lib.types.port;
description = ''
The port that surrealdb will connect to.
'';
default = 8000;
example = 8000;
};
extraFlags = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [];
example = [ "--allow-all" "--user" "root" "--pass" "root" ];
description = ''
Specify a list of additional command line flags.
'';
};
};
};
config = lib.mkIf cfg.enable {
# Used to connect to the running service
environment.systemPackages = [ cfg.package ] ;
systemd.services.surrealdb = {
description = "A scalable, distributed, collaborative, document-graph database, for the realtime web";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
ExecStart = "${cfg.package}/bin/surreal start --bind ${cfg.host}:${toString cfg.port} ${lib.strings.concatStringsSep " " cfg.extraFlags} -- ${cfg.dbPath}";
DynamicUser = true;
Restart = "on-failure";
StateDirectory = "surrealdb";
CapabilityBoundingSet = "";
NoNewPrivileges = true;
PrivateTmp = true;
ProtectHome = true;
ProtectClock = true;
ProtectProc = "noaccess";
ProcSubset = "pid";
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectControlGroups = true;
ProtectHostname = true;
RestrictSUIDSGID = true;
RestrictRealtime = true;
RestrictNamespaces = true;
LockPersonality = true;
RemoveIPC = true;
SystemCallFilter = [ "@system-service" "~@privileged" ];
};
};
};
}
|