nixos/mongodb: use mongosh instead of legacy shell

Niklas Korz 3f8a2242 14b04af9

Changed files
+10 -6
nixos
doc
manual
release-notes
modules
services
databases
+2
nixos/doc/manual/release-notes/rl-2505.section.md
···
- `bind.cacheNetworks` now only controls access for recursive queries, where it previously controlled access for all queries.
+
- [`services.mongodb.enableAuth`](#opt-services.mongodb.enableAuth) now uses the newer [mongosh](https://github.com/mongodb-js/mongosh) shell instead of the legacy shell to configure the initial superuser. You can configure the mongosh package to use through the [`services.mongodb.mongoshPackage`](#opt-services.mongodb.mongoshPackage) option.
+
- The paperless module now has an option for regular automatic export of
documents data using the integrated document exporter.
+8 -6
nixos/modules/services/databases/mongodb.nix
···
mongodb = cfg.package;
+
mongoshExe = lib.getExe cfg.mongoshPackage;
+
mongoCnf =
cfg:
pkgs.writeText "mongodb.conf" ''
···
enable = lib.mkEnableOption "the MongoDB server";
package = lib.mkPackageOption pkgs "mongodb" { };
+
+
mongoshPackage = lib.mkPackageOption pkgs "mongosh" { };
user = lib.mkOption {
type = lib.types.str;
···
};
users.groups.mongodb = lib.mkIf (cfg.user == "mongodb") { };
-
environment.systemPackages = [ mongodb ];
-
systemd.services.mongodb = {
description = "MongoDB server";
···
if ! test -e "${cfg.dbpath}/.auth_setup_complete"; then
systemd-run --unit=mongodb-for-setup --uid=${cfg.user} ${mongodb}/bin/mongod --config ${mongoCnf cfg_}
# wait for mongodb
-
while ! ${mongodb}/bin/mongo --eval "db.version()" > /dev/null 2>&1; do sleep 0.1; done
+
while ! ${mongoshExe} --eval "db.version()" > /dev/null 2>&1; do sleep 0.1; done
-
${mongodb}/bin/mongo <<EOF
-
use admin
+
${mongoshExe} <<EOF
+
use admin;
db.createUser(
{
user: "root",
···
postStart = ''
if test -e "${cfg.dbpath}/.first_startup"; then
${lib.optionalString (cfg.initialScript != null) ''
-
${mongodb}/bin/mongo ${lib.optionalString (cfg.enableAuth) "-u root -p ${cfg.initialRootPassword}"} admin "${cfg.initialScript}"
+
${mongoshExe} ${lib.optionalString (cfg.enableAuth) "-u root -p ${cfg.initialRootPassword}"} admin "${cfg.initialScript}"
''}
rm -f "${cfg.dbpath}/.first_startup"
fi