1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-26 19:16:47 +03:00

nixos/mongodb: use mongosh instead of legacy shell

This commit is contained in:
Niklas Korz 2025-01-21 14:44:10 +01:00
parent 14b04af9f4
commit 3f8a2242b2
2 changed files with 10 additions and 6 deletions

View file

@ -390,6 +390,8 @@
- `bind.cacheNetworks` now only controls access for recursive queries, where it previously controlled access for all queries. - `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 - The paperless module now has an option for regular automatic export of
documents data using the integrated document exporter. documents data using the integrated document exporter.

View file

@ -10,6 +10,8 @@ let
mongodb = cfg.package; mongodb = cfg.package;
mongoshExe = lib.getExe cfg.mongoshPackage;
mongoCnf = mongoCnf =
cfg: cfg:
pkgs.writeText "mongodb.conf" '' pkgs.writeText "mongodb.conf" ''
@ -36,6 +38,8 @@ in
package = lib.mkPackageOption pkgs "mongodb" { }; package = lib.mkPackageOption pkgs "mongodb" { };
mongoshPackage = lib.mkPackageOption pkgs "mongosh" { };
user = lib.mkOption { user = lib.mkOption {
type = lib.types.str; type = lib.types.str;
default = "mongodb"; default = "mongodb";
@ -125,8 +129,6 @@ in
}; };
users.groups.mongodb = lib.mkIf (cfg.user == "mongodb") { }; users.groups.mongodb = lib.mkIf (cfg.user == "mongodb") { };
environment.systemPackages = [ mongodb ];
systemd.services.mongodb = { systemd.services.mongodb = {
description = "MongoDB server"; description = "MongoDB server";
@ -164,10 +166,10 @@ in
if ! test -e "${cfg.dbpath}/.auth_setup_complete"; then if ! test -e "${cfg.dbpath}/.auth_setup_complete"; then
systemd-run --unit=mongodb-for-setup --uid=${cfg.user} ${mongodb}/bin/mongod --config ${mongoCnf cfg_} systemd-run --unit=mongodb-for-setup --uid=${cfg.user} ${mongodb}/bin/mongod --config ${mongoCnf cfg_}
# wait for mongodb # 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 ${mongoshExe} <<EOF
use admin use admin;
db.createUser( db.createUser(
{ {
user: "root", user: "root",
@ -187,7 +189,7 @@ in
postStart = '' postStart = ''
if test -e "${cfg.dbpath}/.first_startup"; then if test -e "${cfg.dbpath}/.first_startup"; then
${lib.optionalString (cfg.initialScript != null) '' ${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" rm -f "${cfg.dbpath}/.first_startup"
fi fi