2022-11-21 17:40:18 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.surrealdb;
|
|
|
|
in {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.surrealdb = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "SurrealDB, a scalable, distributed, collaborative, document-graph database, for the realtime web";
|
2022-11-21 17:40:18 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "surrealdb" { };
|
2022-12-17 10:02:37 +00:00
|
|
|
|
2022-11-21 17:40:18 +00:00
|
|
|
dbPath = mkOption {
|
|
|
|
type = types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
The path that surrealdb will write data to. Use null for in-memory.
|
|
|
|
Can be one of "memory", "file://:path", "tikv://:addr".
|
|
|
|
'';
|
|
|
|
default = "file:///var/lib/surrealdb/";
|
|
|
|
example = "memory";
|
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
The host that surrealdb will connect to.
|
|
|
|
'';
|
|
|
|
default = "127.0.0.1";
|
|
|
|
example = "127.0.0.1";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
The port that surrealdb will connect to.
|
|
|
|
'';
|
|
|
|
default = 8000;
|
|
|
|
example = 8000;
|
|
|
|
};
|
2022-12-17 10:02:37 +00:00
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
extraFlags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "--allow-all" "--auth" "--user root" "--pass root" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-10-09 19:29:22 +00:00
|
|
|
Specify a list of additional command line flags,
|
|
|
|
which get escaped and are then passed to surrealdb.
|
2022-12-17 10:02:37 +00:00
|
|
|
'';
|
|
|
|
};
|
2022-11-21 17:40:18 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
# Used to connect to the running service
|
2022-12-17 10:02:37 +00:00
|
|
|
environment.systemPackages = [ cfg.package ] ;
|
2022-11-21 17:40:18 +00:00
|
|
|
|
|
|
|
systemd.services.surrealdb = {
|
|
|
|
description = "A scalable, distributed, collaborative, document-graph database, for the realtime web ";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
2023-10-09 19:29:22 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/surreal start --bind ${cfg.host}:${toString cfg.port} ${escapeShellArgs cfg.extraFlags} -- ${cfg.dbPath}";
|
2022-11-21 17:40:18 +00:00
|
|
|
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" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|