at 25.11-pre 3.0 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 cfg = config.services.rethinkdb; 9 rethinkdb = cfg.package; 10in 11 12{ 13 14 ###### interface 15 16 options = { 17 18 services.rethinkdb = { 19 20 enable = lib.mkEnableOption "RethinkDB server"; 21 22 #package = lib.mkOption { 23 # default = pkgs.rethinkdb; 24 # description = "Which RethinkDB derivation to use."; 25 #}; 26 27 user = lib.mkOption { 28 default = "rethinkdb"; 29 description = "User account under which RethinkDB runs."; 30 }; 31 32 group = lib.mkOption { 33 default = "rethinkdb"; 34 description = "Group which rethinkdb user belongs to."; 35 }; 36 37 dbpath = lib.mkOption { 38 default = "/var/db/rethinkdb"; 39 description = "Location where RethinkDB stores its data, 1 data directory per instance."; 40 }; 41 42 pidpath = lib.mkOption { 43 default = "/run/rethinkdb"; 44 description = "Location where each instance's pid file is located."; 45 }; 46 47 #cfgpath = lib.mkOption { 48 # default = "/etc/rethinkdb/instances.d"; 49 # description = "Location where RethinkDB stores it config files, 1 config file per instance."; 50 #}; 51 52 # TODO: currently not used by our implementation. 53 #instances = lib.mkOption { 54 # type = lib.types.attrsOf lib.types.str; 55 # default = {}; 56 # description = "List of named RethinkDB instances in our cluster."; 57 #}; 58 59 }; 60 61 }; 62 63 ###### implementation 64 config = lib.mkIf config.services.rethinkdb.enable { 65 66 environment.systemPackages = [ rethinkdb ]; 67 68 systemd.services.rethinkdb = { 69 description = "RethinkDB server"; 70 71 wantedBy = [ "multi-user.target" ]; 72 after = [ "network.target" ]; 73 74 serviceConfig = { 75 # TODO: abstract away 'default', which is a per-instance directory name 76 # allowing end user of this nix module to provide multiple instances, 77 # and associated directory per instance 78 ExecStart = "${rethinkdb}/bin/rethinkdb -d ${cfg.dbpath}/default"; 79 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; 80 User = cfg.user; 81 Group = cfg.group; 82 PIDFile = "${cfg.pidpath}/default.pid"; 83 PermissionsStartOnly = true; 84 }; 85 86 preStart = '' 87 if ! test -e ${cfg.dbpath}; then 88 install -d -m0755 -o ${cfg.user} -g ${cfg.group} ${cfg.dbpath} 89 install -d -m0755 -o ${cfg.user} -g ${cfg.group} ${cfg.dbpath}/default 90 chown -R ${cfg.user}:${cfg.group} ${cfg.dbpath} 91 fi 92 if ! test -e "${cfg.pidpath}/default.pid"; then 93 install -D -o ${cfg.user} -g ${cfg.group} /dev/null "${cfg.pidpath}/default.pid" 94 fi 95 ''; 96 }; 97 98 users.users.rethinkdb = lib.mkIf (cfg.user == "rethinkdb") { 99 name = "rethinkdb"; 100 description = "RethinkDB server user"; 101 isSystemUser = true; 102 }; 103 104 users.groups = lib.optionalAttrs (cfg.group == "rethinkdb") ( 105 lib.singleton { 106 name = "rethinkdb"; 107 } 108 ); 109 110 }; 111 112}