1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-21 08:59:20 +03:00
nixpkgs/nixos/modules/services/databases/surrealdb.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

104 lines
2.7 KiB
Nix
Raw Normal View History

2022-11-19 18:33:18 -05:00
{
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";
2022-11-19 18:33:18 -05:00
package = lib.mkPackageOption pkgs "surrealdb" { };
2022-12-15 15:57:41 -05:00
dbPath = lib.mkOption {
type = lib.types.str;
2022-11-19 18:33:18 -05:00
description = ''
The path that surrealdb will write data to. Use null for in-memory.
2024-10-31 13:12:53 -05:00
Can be one of "memory", "rocksdb://:path", "surrealkv://:path", "tikv://:addr", "fdb://:addr".
2022-11-19 18:33:18 -05:00
'';
2024-10-31 13:12:53 -05:00
default = "rocksdb:///var/lib/surrealdb/";
2022-11-19 18:33:18 -05:00
example = "memory";
};
host = lib.mkOption {
type = lib.types.str;
2022-11-19 18:33:18 -05:00
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;
2022-11-19 18:33:18 -05:00
description = ''
The port that surrealdb will connect to.
'';
default = 8000;
example = 8000;
};
extraFlags = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
2024-10-31 13:12:53 -05:00
example = [
"--allow-all"
"--user"
"root"
"--pass"
"root"
];
description = ''
2024-10-31 13:12:53 -05:00
Specify a list of additional command line flags.
'';
};
2022-11-19 18:33:18 -05:00
};
};
config = lib.mkIf cfg.enable {
2022-11-19 18:33:18 -05:00
# Used to connect to the running service
2022-12-15 15:57:41 -05:00
environment.systemPackages = [ cfg.package ];
2022-11-19 18:33:18 -05:00
systemd.services.surrealdb = {
description = "A scalable, distributed, collaborative, document-graph database, for the realtime web";
2022-11-19 18:33:18 -05:00
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
2024-10-31 13:12:53 -05:00
ExecStart = "${cfg.package}/bin/surreal start --bind ${cfg.host}:${toString cfg.port} ${lib.strings.concatStringsSep " " cfg.extraFlags} -- ${cfg.dbPath}";
2022-11-19 18:33:18 -05: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"
];
};
};
};
}