at 17.09-beta 4.6 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.riak-cs; 8 9in 10 11{ 12 13 ###### interface 14 15 options = { 16 17 services.riak-cs = { 18 19 enable = mkEnableOption "riak-cs"; 20 21 package = mkOption { 22 type = types.package; 23 default = pkgs.riak-cs; 24 defaultText = "pkgs.riak-cs"; 25 example = literalExample "pkgs.riak-cs"; 26 description = '' 27 Riak package to use. 28 ''; 29 }; 30 31 nodeName = mkOption { 32 type = types.str; 33 default = "riak-cs@127.0.0.1"; 34 description = '' 35 Name of the Erlang node. 36 ''; 37 }; 38 39 anonymousUserCreation = mkOption { 40 type = types.bool; 41 default = false; 42 description = '' 43 Anonymous user creation. 44 ''; 45 }; 46 47 riakHost = mkOption { 48 type = types.str; 49 default = "127.0.0.1:8087"; 50 description = '' 51 Name of riak hosting service. 52 ''; 53 }; 54 55 listener = mkOption { 56 type = types.str; 57 default = "127.0.0.1:8080"; 58 description = '' 59 Name of Riak CS listening service. 60 ''; 61 }; 62 63 stanchionHost = mkOption { 64 type = types.str; 65 default = "127.0.0.1:8085"; 66 description = '' 67 Name of stanchion hosting service. 68 ''; 69 }; 70 71 stanchionSsl = mkOption { 72 type = types.bool; 73 default = true; 74 description = '' 75 Tell stanchion to use SSL. 76 ''; 77 }; 78 79 distributedCookie = mkOption { 80 type = types.str; 81 default = "riak"; 82 description = '' 83 Cookie for distributed node communication. All nodes in the 84 same cluster should use the same cookie or they will not be able to 85 communicate. 86 ''; 87 }; 88 89 dataDir = mkOption { 90 type = types.path; 91 default = "/var/db/riak-cs"; 92 description = '' 93 Data directory for Riak CS. 94 ''; 95 }; 96 97 logDir = mkOption { 98 type = types.path; 99 default = "/var/log/riak-cs"; 100 description = '' 101 Log directory for Riak CS. 102 ''; 103 }; 104 105 extraConfig = mkOption { 106 type = types.lines; 107 default = ""; 108 description = '' 109 Additional text to be appended to <filename>riak-cs.conf</filename>. 110 ''; 111 }; 112 113 extraAdvancedConfig = mkOption { 114 type = types.lines; 115 default = ""; 116 description = '' 117 Additional text to be appended to <filename>advanced.config</filename>. 118 ''; 119 }; 120 }; 121 122 }; 123 124 ###### implementation 125 126 config = mkIf cfg.enable { 127 128 environment.systemPackages = [ cfg.package ]; 129 environment.etc."riak-cs/riak-cs.conf".text = '' 130 nodename = ${cfg.nodeName} 131 distributed_cookie = ${cfg.distributedCookie} 132 133 platform_log_dir = ${cfg.logDir} 134 135 riak_host = ${cfg.riakHost} 136 listener = ${cfg.listener} 137 stanchion_host = ${cfg.stanchionHost} 138 139 anonymous_user_creation = ${if cfg.anonymousUserCreation then "on" else "off"} 140 141 ${cfg.extraConfig} 142 ''; 143 144 environment.etc."riak-cs/advanced.config".text = '' 145 ${cfg.extraAdvancedConfig} 146 ''; 147 148 users.extraUsers.riak-cs = { 149 name = "riak-cs"; 150 uid = config.ids.uids.riak-cs; 151 group = "riak"; 152 description = "Riak CS server user"; 153 }; 154 155 systemd.services.riak-cs = { 156 description = "Riak CS Server"; 157 158 wantedBy = [ "multi-user.target" ]; 159 after = [ "network.target" ]; 160 161 path = [ 162 pkgs.utillinux # for `logger` 163 pkgs.bash 164 ]; 165 166 environment.HOME = "${cfg.dataDir}"; 167 environment.RIAK_CS_DATA_DIR = "${cfg.dataDir}"; 168 environment.RIAK_CS_LOG_DIR = "${cfg.logDir}"; 169 environment.RIAK_CS_ETC_DIR = "/etc/riak"; 170 171 preStart = '' 172 if ! test -e ${cfg.logDir}; then 173 mkdir -m 0755 -p ${cfg.logDir} 174 chown -R riak-cs ${cfg.logDir} 175 fi 176 177 if ! test -e ${cfg.dataDir}; then 178 mkdir -m 0700 -p ${cfg.dataDir} 179 chown -R riak-cs ${cfg.dataDir} 180 fi 181 ''; 182 183 serviceConfig = { 184 ExecStart = "${cfg.package}/bin/riak-cs console"; 185 ExecStop = "${cfg.package}/bin/riak-cs stop"; 186 StandardInput = "tty"; 187 User = "riak-cs"; 188 Group = "riak-cs"; 189 PermissionsStartOnly = true; 190 # Give Riak a decent amount of time to clean up. 191 TimeoutStopSec = 120; 192 LimitNOFILE = 65536; 193 }; 194 195 unitConfig.RequiresMountsFor = [ 196 "${cfg.dataDir}" 197 "${cfg.logDir}" 198 "/etc/riak" 199 ]; 200 }; 201 }; 202}