1 { config, lib, pkgs, ... }:
4 cfg = config.services.surrealdb;
9 enable = lib.mkEnableOption "SurrealDB, a scalable, distributed, collaborative, document-graph database, for the realtime web";
11 package = lib.mkPackageOption pkgs "surrealdb" { };
13 dbPath = lib.mkOption {
16 The path that surrealdb will write data to. Use null for in-memory.
17 Can be one of "memory", "file://:path", "tikv://:addr".
19 default = "file:///var/lib/surrealdb/";
26 The host that surrealdb will connect to.
28 default = "127.0.0.1";
29 example = "127.0.0.1";
33 type = lib.types.port;
35 The port that surrealdb will connect to.
41 extraFlags = lib.mkOption {
42 type = lib.types.listOf lib.types.str;
44 example = [ "--allow-all" "--auth" "--user root" "--pass root" ];
46 Specify a list of additional command line flags,
47 which get escaped and are then passed to surrealdb.
53 config = lib.mkIf cfg.enable {
55 # Used to connect to the running service
56 environment.systemPackages = [ cfg.package ] ;
58 systemd.services.surrealdb = {
59 description = "A scalable, distributed, collaborative, document-graph database, for the realtime web";
60 wantedBy = [ "multi-user.target" ];
61 after = [ "network.target" ];
64 ExecStart = "${cfg.package}/bin/surreal start --bind ${cfg.host}:${toString cfg.port} ${lib.escapeShellArgs cfg.extraFlags} -- ${cfg.dbPath}";
66 Restart = "on-failure";
67 StateDirectory = "surrealdb";
68 CapabilityBoundingSet = "";
69 NoNewPrivileges = true;
73 ProtectProc = "noaccess";
75 ProtectKernelLogs = true;
76 ProtectKernelModules = true;
77 ProtectKernelTunables = true;
78 ProtectControlGroups = true;
79 ProtectHostname = true;
80 RestrictSUIDSGID = true;
81 RestrictRealtime = true;
82 RestrictNamespaces = true;
83 LockPersonality = true;
85 SystemCallFilter = [ "@system-service" "~@privileged" ];