Unifi controller won't start, howto specify mongodb-ce version

Hi!

I am using nixos-24.11 packages in my flake. I have

  services.unifi = {
    enable = true;
    unifiPackage = pkgs.unifi8;
    # mongodb-7_0 is not available precompiled and compiling takes dozens of GB RAM and disk space
    # use mongodb-ce instead:
    mongodbPackage = pkgs.mongodb-ce;
    openFirewall = true;
  };

However the unifi service never fully starts. I can not reach the unifi controller webinterface on port 8443.

/var/log/unifi/server.log keeps repeating those lines:

[2025-04-19T17:49:18,490+02:00] <mongod-tail> WARN  mongo  - Mongo log not found during startup
[2025-04-19T17:49:18,591+02:00] <mongod-tail> WARN  mongo  - Mongo log not found during startup
[2025-04-19T17:49:18,691+02:00] <mongod-tail> WARN  mongo  - Mongo log not found during startup
[2025-04-19T17:49:18,792+02:00] <mongod-tail> WARN  mongo  - Mongo log not found during startup
[2025-04-19T17:49:18,892+02:00] <mongod-tail> WARN  mongo  - Mongo log not found during startup
[2025-04-19T17:49:18,974+02:00] <mongo-db> WARN  mongo  - Stop listening to Mongo logs after process has exited
[2025-04-19T17:49:18,974+02:00] <mongo-db> INFO  mongo  - Database process stopped, code=132

So I wanted to try to downgrade the mongodb package from 8.x to 7x and see if that works arround the issue. My problem is I am new to nixos and don’t know how to specify the mongodb-ce version for unifi.
This didn’t work: mongodbPackage = pkgs.mongodb-ce.override { version = "7.0.14"; };
Can I only do this via the lock file?

I have now downgraded to version 7.0.14 but the error remains.

Database process stopped, code=132

132 doesn’t seem to be a documented mongod process exit code: Exit Codes and Statuses for a Self-Managed Deployment - Database Manual v8.0 - MongoDB Docs

I am also seeing at least 60 mongodb coredump files like this:

./lib/systemd/coredump/core.mongod.995.62d90c0cfc80410ca0ecfa74259d6468.2764396.1745174687000000.zst

I installed mongodb-ce as separate package, and upgraded and tested both stable and unstable.
I keep getting errors like this:

Process 43215 (mongod) of user 994 dumped core.
                                                     
        Module libbrotlicommon.so.1 without build-id.
        Module libkeyutils.so.1 without build-id.
        Module libkrb5support.so.0 without build-id.
        Module libcom_err.so.3 without build-id.
        Module libk5crypto.so.3 without build-id.
        Module libkrb5.so.3 without build-id.
        Module libunistring.so.5 without build-id.
        Module libz.so.1 without build-id.
        Module libbrotlidec.so.1 without build-id.
        Module libzstd.so.1 without build-id.
        Module libgssapi_krb5.so.2 without build-id.
        Module libpsl.so.5 without build-id.
        Module libssh2.so.1 without build-id.
        Module libidn2.so.0 without build-id.
        Module libnghttp2.so.14 without build-id.
        Module libgcc_s.so.1 without build-id.
        Stack trace of thread 43215:
        #0  0x000055c94bde0e9d _ZN8tcmalloc17tcmalloc_internal12ParseCpulistEN4absl12lts_2023080211FunctionRefIFlPcmEEE (/nix/store/fk09wn7jl7rq56w9584h7vg03j0pn6ks-mongodb-ce-8.0.4/bin/mongod + 0x905ce9d)
        #1  0x000055c94bde10be _ZN8tcmalloc17tcmalloc_internal16sysinfo_internal22NumPossibleCPUsNoCacheEv (/nix/store/fk09wn7jl7rq56w9584h7vg03j0pn6ks-mongodb-ce-8.0.4/bin/mongod + 0x905d0be)
        #2  0x000055c94bdd648e _ZN4absl12lts_2023080213base_internal12CallOnceImplIZN8tcmalloc17tcmalloc_internal7NumCPUsEvEUlvE_JEEEvPSt6atomicIjENS1_14SchedulingModeEOT_DpOT0_.isra.0 (/nix/store/fk09wn7jl7rq56w9584h7vg03j0pn6ks-mongodb-ce-8.0.4/bin/mongod + 0x905248e)
        #3  0x000055c94bdd65a5 _ZN8tcmalloc17tcmalloc_internal6Static19SlowInitIfNecessaryEv (/nix/store/fk09wn7jl7rq56w9584h7vg03j0pn6ks-mongodb-ce-8.0.4/bin/mongod + 0x90525a5)
        #4  0x000055c94bdd348f _ZN8tcmalloc17tcmalloc_internal7Sampler4InitEm (/nix/store/fk09wn7jl7rq56w9584h7vg03j0pn6ks-mongodb-ce-8.0.4/bin/mongod + 0x904f48f)
        #5  0x000055c94bdd35a0 _ZN8tcmalloc17tcmalloc_internal7Sampler20RecordAllocationSlowEm (/nix/store/fk09wn7jl7rq56w9584h7vg03j0pn6ks-mongodb-ce-8.0.4/bin/mongod + 0x904f5a0)
        #6  0x000055c94bd87321 _ZN8tcmalloc17tcmalloc_internalL16slow_alloc_smallINS0_14TCMallocPolicyINS0_12CppOomPolicyENS0_18DefaultAlignPolicyENS0_25AllocationAccessHotPolicyENS0_17InvokeHooksPolicyENS0_22NonSizeReturningPolicyENS0_24LocalNumaPartitionPolicyEEEEENT_12pointer_typeEmjSA_.constprop.0 (/nix/store/fk09wn7jl7rq56w9584h7vg03j0pn6ks-mongodb-ce-8.0.4/bin/mongod + 0x9003321)
        #7  0x000055c947458b12 _Z41__static_initialization_and_destruction_0ii.constprop.0 (/nix/store/fk09wn7jl7rq56w9584h7vg03j0pn6ks-mongodb-ce-8.0.4/bin/mongod + 0x46d4b12)
        #8  0x00007ff77d02a5ae __libc_start_main@@GLIBC_2.34 (libc.so.6 + 0x2a5ae)
        #9  0x000055c94743ce25 _start (/nix/store/fk09wn7jl7rq56w9584h7vg03j0pn6ks-mongodb-ce-8.0.4/bin/mongod + 0x46b8e25)
        ELF object binary architecture: AMD x86-64

Okay so the issue causing the mongodb crashes was not exposing the AVX cpuinfo flag to the VM that nixos runs in. AVX is a minimum requirement for mongodb.

Besides that I also had to add
networking.firewall.allowedTCPPorts = [ 8443 ];
since this is not done automatically by services.unifi.openFirewall (it pays to read documentation)

Now everything works, except some occasional IllegalStateExceptions, that don’t affect normal operation as far as I can tell.

Mai 05 04:47:39 nixos-unifi java[892]: Exception in thread “Thread-12” java.lang.IllegalStateException: BeanFactory not initialized or already closed - call ‘refresh’ before accessing beans via the ApplicationContext
Mai 05 04:47:39 nixos-unifi java[892]: at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:169)
Mai 05 04:47:39 nixos-unifi java[892]: at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1252)
Mai 05 04:47:39 nixos-unifi java[892]: at com.ubnt.service.ooOO.Ö00000(Unknown Source)
Mai 05 04:47:39 nixos-unifi java[892]: at com.ubnt.ace.Launcher.Ò00000(Unknown Source)
Mai 05 04:47:39 nixos-unifi java[892]: at java.base/java.lang.Thread.run(Thread.java:840)

1 Like