1 { config, lib, pkgs, ... }:
3 cfg = config.services.rethinkdb;
4 rethinkdb = cfg.package;
13 services.rethinkdb = {
15 enable = lib.mkEnableOption "RethinkDB server";
17 #package = lib.mkOption {
18 # default = pkgs.rethinkdb;
19 # description = "Which RethinkDB derivation to use.";
23 default = "rethinkdb";
24 description = "User account under which RethinkDB runs.";
27 group = lib.mkOption {
28 default = "rethinkdb";
29 description = "Group which rethinkdb user belongs to.";
32 dbpath = lib.mkOption {
33 default = "/var/db/rethinkdb";
34 description = "Location where RethinkDB stores its data, 1 data directory per instance.";
37 pidpath = lib.mkOption {
38 default = "/run/rethinkdb";
39 description = "Location where each instance's pid file is located.";
42 #cfgpath = lib.mkOption {
43 # default = "/etc/rethinkdb/instances.d";
44 # description = "Location where RethinkDB stores it config files, 1 config file per instance.";
47 # TODO: currently not used by our implementation.
48 #instances = lib.mkOption {
49 # type = lib.types.attrsOf lib.types.str;
51 # description = "List of named RethinkDB instances in our cluster.";
59 config = lib.mkIf config.services.rethinkdb.enable {
61 environment.systemPackages = [ rethinkdb ];
63 systemd.services.rethinkdb = {
64 description = "RethinkDB server";
66 wantedBy = [ "multi-user.target" ];
67 after = [ "network.target" ];
70 # TODO: abstract away 'default', which is a per-instance directory name
71 # allowing end user of this nix module to provide multiple instances,
72 # and associated directory per instance
73 ExecStart = "${rethinkdb}/bin/rethinkdb -d ${cfg.dbpath}/default";
74 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
77 PIDFile = "${cfg.pidpath}/default.pid";
78 PermissionsStartOnly = true;
82 if ! test -e ${cfg.dbpath}; then
83 install -d -m0755 -o ${cfg.user} -g ${cfg.group} ${cfg.dbpath}
84 install -d -m0755 -o ${cfg.user} -g ${cfg.group} ${cfg.dbpath}/default
85 chown -R ${cfg.user}:${cfg.group} ${cfg.dbpath}
87 if ! test -e "${cfg.pidpath}/default.pid"; then
88 install -D -o ${cfg.user} -g ${cfg.group} /dev/null "${cfg.pidpath}/default.pid"
93 users.users.rethinkdb = lib.mkIf (cfg.user == "rethinkdb")
95 description = "RethinkDB server user";
99 users.groups = lib.optionalAttrs (cfg.group == "rethinkdb") (lib.singleton
100 { name = "rethinkdb";