Matter server weird permission issues

Enabled the server:

  services.matter-server.enable = true;

systemd unit log output:

Started Matter Server.
(MainThread) INFO [matter_server.server.stack] Initializing CHIP/Matter Logging...
(MainThread) INFO [matter_server.server.stack] Initializing CHIP/Matter Controller Stack...
(MainThread) DEBUG [matter_server.server.stack] Using storage file: /var/lib/matter-server/chip.json - Bluetooth commissioning enabled: NO
[1741533508.087392][2017658:2017658] CHIP:CTL: Setting attestation nonce to random value
[1741533508.087416][2017658:2017658] CHIP:CTL: Setting CSR nonce to random value
[1741533508.087860][2017658:2017658] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /tmp/chip_kvs
[1741533508.152061][2017658:2017658] CHIP:DL: Wrote settings to /tmp/chip_kvs
[1741533508.152194][2017658:2017658] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /data/chip_factory.ini
[1741533508.152233][2017658:2017658] CHIP:DL: Failed to create temp file /data/chip_factory.ini-BoBS9C: Permission denied

And then dies.

The /var/lib/matter-server folder/symlink did not exist before.
Afterwards permissions look like this:

$ ll /var/lib/
lrwxrwxrwx  1 root            root            21  9. Mär 16:18 matter-server -> private/matter-server
$ ll /var/lib/private
drwxr-xr-x 2 nobody nogroup 2  9. Mär 16:18 matter-server
$ ll /var/lib/private/matter-server
<empty>

systemctl cat matter-server.service:

# /etc/systemd/system/matter-server.service
[Unit]
After=network-online.target
Before=home-assistant.service
Description=Matter Server
Wants=network-online.target

[Service]
Environment="HOME=/var/lib/matter-server"
Environment="LOCALE_ARCHIVE=/nix/store/i7inm24z817bdph4c8niqld7ydsv1f5y-glibc-locales-2.40-66/lib/locale/locale-archive"
Environment="PATH=/nix/store/fr9yr63a1267cr0r86w18c77mh3xavcc-coreutils-9.6/bin:/nix/store/lk2sg2yq5jqs9dlx5ini46kvjwk7ffsf-findutils-4.10.0/bin:/nix/store/yz6nq9v29l3g990w8zlqsnzl>
Environment="TZDIR=/nix/store/pzi38xllbgp4pisk17l4hi28mhr67xkq-tzdata-2025a/share/zoneinfo"
AmbientCapabilities=
BindPaths=/var/lib/matter-server:/data
CapabilityBoundingSet=
DevicePolicy=closed
DynamicUser=true
ExecStart=/nix/store/lpk47l0bwrgxzik2vsy46z4nzs2nb7yp-python3.12-python-matter-server-7.0.1/bin/matter-server --port 5580 --vendorid 4939 --storage-path /var/lib/matter-server  --log-level debug
LockPersonality=true
MemoryDenyWriteExecute=true
NoNewPrivileges=true
PrivateDevices=true
PrivateTmp=true
PrivateUsers=true
ProcSubset=pid
ProtectClock=true
ProtectControlGroups=true
ProtectHome=true
ProtectHostname=true
ProtectKernelLogs=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectProc=invisible
ReadOnlyPaths=/nix/store /run/dbus
RestrictAddressFamilies=AF_INET
RestrictAddressFamilies=AF_INET6
RestrictAddressFamilies=AF_NETLINK
RestrictAddressFamilies=AF_UNIX
RestrictNamespaces=true
RestrictRealtime=true
RestrictSUIDSGID=true
StateDirectory=matter-server
SystemCallFilter=~ @clock @cpu-emulation @debug @module @mount @obsolete @privileged @raw-io @reboot @resources @swap
TemporaryFileSystem=/
UMask=0077

[Install]
WantedBy=multi-user.target

Since the unit uses DynamicUser=true the /var/lib/matter-server/folder is symlinked and always chowned to the random user when the systemd unit starts. And BindPaths=/var/lib/matter-server:/data binds /data to that folder.

So why does the user not have write permission to that folder? And since everything is created automatically from systemd why do no others face that issue?
Any ideas? Or an idea how to debug this?

A fix was prepared and needs review in

The fix to switch off dynamic user yields:

matter-server.service: Failed to set up mount namespacing: /nix/store: No such file or directory
matter-server.service: Failed at step NAMESPACE spawning /nix/store/lpk47l0bwrgxzik2vsy46z4nzs2nb7yp-python3.12-python-matter-server-7.0.1/bin/matter-server: No such file or directory

But a comment mentions it is solved differently. I will dig deeper.

Update: this fix works indeed! But only all changes not just switch off dynamic user. Thx!