8 cfg = config.services.dgraph;
9 settingsFormat = pkgs.formats.json { };
10 configFile = settingsFormat.generate "config.json" cfg.settings;
12 pkgs.runCommand "dgraph"
14 nativeBuildInputs = [ pkgs.makeWrapper ];
18 makeWrapper ${cfg.package}/bin/dgraph $out/bin/dgraph \
19 --prefix PATH : "${lib.makeBinPath [ pkgs.nodejs ]}" \
22 NoNewPrivileges = true;
24 AmbientCapabilities = "";
25 CapabilityBoundingSet = "";
29 LockPersonality = true;
32 PrivateDevices = true;
36 ProtectControlGroups = true;
37 ProtectHostname = true;
38 ProtectKernelLogs = true;
39 ProtectKernelModules = true;
40 ProtectKernelTunables = true;
44 RestrictNamespaces = true;
45 RestrictAddressFamilies = [
50 RestrictRealtime = true;
51 RestrictSUIDSGID = true;
53 SystemCallArchitectures = "native";
54 SystemCallErrorNumber = "EPERM";
70 enable = lib.mkEnableOption "Dgraph native GraphQL database with a graph backend";
72 package = lib.mkPackageOption pkgs "dgraph" { };
74 settings = lib.mkOption {
75 type = settingsFormat.type;
78 Contents of the dgraph config. For more details see https://dgraph.io/docs/deploy/config
85 default = "localhost";
87 The host which dgraph alpha will be run on.
91 type = lib.types.port;
94 The port which to run dgraph alpha on.
101 host = lib.mkOption {
102 type = lib.types.str;
103 default = "localhost";
105 The host which dgraph zero will be run on.
108 port = lib.mkOption {
109 type = lib.types.port;
112 The port which to run dgraph zero on.
120 config = lib.mkIf cfg.enable {
121 services.dgraph.settings = {
122 badger.compression = lib.mkDefault "zstd:3";
125 systemd.services.dgraph-zero = {
126 description = "Dgraph native GraphQL database with a graph backend. Zero controls node clustering";
127 after = [ "network.target" ];
128 wantedBy = [ "multi-user.target" ];
131 StateDirectory = "dgraph-zero";
132 WorkingDirectory = "/var/lib/dgraph-zero";
134 ExecStart = "${cfg.package}/bin/dgraph zero --my ${cfg.zero.host}:${toString cfg.zero.port}";
135 Restart = "on-failure";
136 } // securityOptions;
139 systemd.services.dgraph-alpha = {
140 description = "Dgraph native GraphQL database with a graph backend. Alpha serves data";
143 "dgraph-zero.service"
145 requires = [ "dgraph-zero.service" ];
146 wantedBy = [ "multi-user.target" ];
149 StateDirectory = "dgraph-alpha";
150 WorkingDirectory = "/var/lib/dgraph-alpha";
152 ExecStart = "${dgraphWithNode}/bin/dgraph alpha --config ${configFile} --my ${cfg.alpha.host}:${toString cfg.alpha.port} --zero ${cfg.zero.host}:${toString cfg.zero.port}";
154 ${pkgs.curl}/bin/curl --data "mutation { shutdown { response { message code } } }" \
155 --header 'Content-Type: application/graphql' \
157 http://localhost:8080/admin
159 Restart = "on-failure";
160 } // securityOptions;
164 meta.maintainers = with lib.maintainers; [ happysalada ];