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", "rocksdb://:path", "surrealkv://:path", "tikv://:addr", "fdb://:addr".
19 default = "rocksdb:///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" "--user" "root" "--pass" "root" ];
46 Specify a list of additional command line flags.
52 config = lib.mkIf cfg.enable {
54 # Used to connect to the running service
55 environment.systemPackages = [ cfg.package ] ;
57 systemd.services.surrealdb = {
58 description = "A scalable, distributed, collaborative, document-graph database, for the realtime web";
59 wantedBy = [ "multi-user.target" ];
60 after = [ "network.target" ];
63 ExecStart = "${cfg.package}/bin/surreal start --bind ${cfg.host}:${toString cfg.port} ${lib.strings.concatStringsSep " " cfg.extraFlags} -- ${cfg.dbPath}";
65 Restart = "on-failure";
66 StateDirectory = "surrealdb";
67 CapabilityBoundingSet = "";
68 NoNewPrivileges = true;
72 ProtectProc = "noaccess";
74 ProtectKernelLogs = true;
75 ProtectKernelModules = true;
76 ProtectKernelTunables = true;
77 ProtectControlGroups = true;
78 ProtectHostname = true;
79 RestrictSUIDSGID = true;
80 RestrictRealtime = true;
81 RestrictNamespaces = true;
82 LockPersonality = true;
84 SystemCallFilter = [ "@system-service" "~@privileged" ];