diff --git a/nixos/doc/manual/release-notes/rl-2505.section.md b/nixos/doc/manual/release-notes/rl-2505.section.md index 18277e877340..1277d6d8eda8 100644 --- a/nixos/doc/manual/release-notes/rl-2505.section.md +++ b/nixos/doc/manual/release-notes/rl-2505.section.md @@ -226,6 +226,8 @@ - `racket_7_9` has been removed, as it is insecure. It is recommended to use Racket 8 instead. +- `services.mongodb.initialRootPassword` has been replaced with the more secure option [`services.mongodb.initialRootPasswordFile`](#opt-services.mongodb.initialRootPasswordFile) + - `rofi` has been updated from 1.7.5 to 1.7.6 which introduces some breaking changes to binary plugins, and also contains a lot of new features and bug fixes. This is highlighted because the patch version bump does not indicate the volume of changes by itself. See the [upstream release notes](https://github.com/davatorium/rofi/releases/tag/1.7.6) for the full list of changes. - `ente-auth` now uses the name `enteauth` for its binary. The previous name was `ente_auth`. @@ -386,6 +388,8 @@ - GOverlay has been updated to 1.2, please check the [upstream changelog](https://github.com/benjamimgois/goverlay/releases) for more details. +- [`services.mongodb`](#opt-services.mongodb.enable) is now compatible with the `mongodb-ce` binary package. To make use of it, set [`services.mongodb.package`](#opt-services.mongodb.package) to `pkgs.mongodb-ce`. + - [`services.jupyter`](#opt-services.jupyter.enable) is now compatible with `Jupyter Notebook 7`. See [the migration guide](https://jupyter-notebook.readthedocs.io/en/latest/migrate_to_notebook7.html) for details. - `networking.wireguard` now has an optional networkd backend. It is enabled by default when `networking.useNetworkd` is enabled, and it can be enabled alongside scripted networking with `networking.wireguard.useNetworkd`. Some `networking.wireguard` options have slightly different behavior with the networkd and script-based backends, documented in each option. @@ -398,6 +402,8 @@ - `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. diff --git a/nixos/modules/services/databases/mongodb.nix b/nixos/modules/services/databases/mongodb.nix index 90b749574bf5..129b679d73f8 100644 --- a/nixos/modules/services/databases/mongodb.nix +++ b/nixos/modules/services/databases/mongodb.nix @@ -10,6 +10,8 @@ let mongodb = cfg.package; + mongoshExe = lib.getExe cfg.mongoshPackage; + mongoCnf = cfg: pkgs.writeText "mongodb.conf" '' @@ -25,6 +27,13 @@ let in { + imports = [ + (lib.mkRemovedOptionModule [ + "services" + "mongodb" + "initialRootPassword" + ] "Use services.mongodb.initialRootPasswordFile to securely provide the initial root password.") + ]; ###### interface @@ -34,7 +43,11 @@ in enable = lib.mkEnableOption "the MongoDB server"; - package = lib.mkPackageOption pkgs "mongodb" { }; + package = lib.mkPackageOption pkgs "mongodb" { + example = "pkgs.mongodb-ce"; + }; + + mongoshPackage = lib.mkPackageOption pkgs "mongosh" { }; user = lib.mkOption { type = lib.types.str; @@ -60,10 +73,10 @@ in description = "Enable client authentication. Creates a default superuser with username root!"; }; - initialRootPassword = lib.mkOption { - type = lib.types.nullOr lib.types.str; + initialRootPasswordFile = lib.mkOption { + type = lib.types.nullOr lib.types.path; default = null; - description = "Password for the root user if auth is enabled."; + description = "Path to the file containing the password for the root user if auth is enabled."; }; dbpath = lib.mkOption { @@ -112,8 +125,8 @@ in config = lib.mkIf config.services.mongodb.enable { assertions = [ { - assertion = !cfg.enableAuth || cfg.initialRootPassword != null; - message = "`enableAuth` requires `initialRootPassword` to be set."; + assertion = !cfg.enableAuth || cfg.initialRootPasswordFile != null; + message = "`enableAuth` requires `initialRootPasswordFile` to be set."; } ]; @@ -125,8 +138,6 @@ in }; users.groups.mongodb = lib.mkIf (cfg.user == "mongodb") { }; - environment.systemPackages = [ mongodb ]; - systemd.services.mongodb = { description = "MongoDB server"; @@ -164,14 +175,15 @@ in 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 <