Merge pull request #200319 from helsinki-systems/feat/redis-module-changes

nixos/redis: misc module changes

authored by Janne Heß and committed by GitHub 798bc67c 1f6b9828

+34 -10
+7
nixos/doc/manual/from_md/release-notes/rl-2211.section.xml
··· 1191 1191 </listitem> 1192 1192 <listitem> 1193 1193 <para> 1194 + The redis module now persists each instance’s configuration 1195 + file in the state directory, in order to support some more 1196 + advanced use cases like sentinel. 1197 + </para> 1198 + </listitem> 1199 + <listitem> 1200 + <para> 1194 1201 The udisks2 service, available at 1195 1202 <literal>services.udisks2.enable</literal>, is now disabled by 1196 1203 default. It will automatically be enabled through services and
+2
nixos/doc/manual/release-notes/rl-2211.section.md
··· 362 362 363 363 - The `documentation.nixos.options.allowDocBook` option was added to ease the transition to CommonMark option documentation. Setting this option to `false` causes an error for every option included in the manual that uses DocBook documentation; it defaults to `true` to preserve the previous behavior and will be removed once the transition to CommonMark is complete. 364 364 365 + - The redis module now persists each instance's configuration file in the state directory, in order to support some more advanced use cases like sentinel. 366 + 365 367 - The udisks2 service, available at `services.udisks2.enable`, is now disabled by default. It will automatically be enabled through services and desktop environments as needed. 366 368 This also means that polkit will now actually be disabled by default. The default for `security.polkit.enable` was already flipped in the previous release, but udisks2 being enabled by default re-enabled it. 367 369
+25 -10
nixos/modules/services/databases/redis.nix
··· 105 105 ''; 106 106 }; 107 107 108 + extraParams = mkOption { 109 + type = with types; listOf str; 110 + default = []; 111 + description = lib.mdDoc "Extra parameters to append to redis-server invocation"; 112 + example = [ "--sentinel" ]; 113 + }; 114 + 108 115 bind = mkOption { 109 116 type = with types; nullOr str; 110 117 default = "127.0.0.1"; ··· 340 347 after = [ "network.target" ]; 341 348 342 349 serviceConfig = { 343 - ExecStart = "${cfg.package}/bin/redis-server /run/${redisName name}/redis.conf"; 344 - ExecStartPre = [("+"+pkgs.writeShellScript "${redisName name}-credentials" ('' 345 - install -o '${conf.user}' -m 600 ${redisConfig conf.settings} /run/${redisName name}/redis.conf 346 - '' + optionalString (conf.requirePassFile != null) '' 347 - { 348 - printf requirePass' ' 349 - cat ${escapeShellArg conf.requirePassFile} 350 - } >>/run/${redisName name}/redis.conf 351 - '') 352 - )]; 350 + ExecStart = "${cfg.package}/bin/redis-server /var/lib/${redisName name}/redis.conf ${escapeShellArgs conf.extraParams}"; 351 + ExecStartPre = "+"+pkgs.writeShellScript "${redisName name}-prep-conf" (let 352 + redisConfVar = "/var/lib/${redisName name}/redis.conf"; 353 + redisConfRun = "/run/${redisName name}/nixos.conf"; 354 + redisConfStore = redisConfig conf.settings; 355 + in '' 356 + touch "${redisConfVar}" "${redisConfRun}" 357 + chown '${conf.user}' "${redisConfVar}" "${redisConfRun}" 358 + chmod 0600 "${redisConfVar}" "${redisConfRun}" 359 + if [ ! -s ${redisConfVar} ]; then 360 + echo 'include "${redisConfRun}"' > "${redisConfVar}" 361 + fi 362 + echo 'include "${redisConfStore}"' > "${redisConfRun}" 363 + ${optionalString (conf.requirePassFile != null) '' 364 + {echo -n "requirepass " 365 + cat ${escapeShellArg conf.requirePassFile}} >> "${redisConfRun}" 366 + ''} 367 + ''); 353 368 Type = "notify"; 354 369 # User and group 355 370 User = conf.user;