"Error: Failed to open unit file" when mounting a CIFS filesystem

Hi,

I’m a long time Linux user but relatively new to NixOS. I got very far now but I need some help to get around this problem.

I’m trying to mount a samba share with the following nix module (about the same as described in the wiki: Samba - NixOS Wiki), but I get an error when running nixos-rebuild switch:

{ config, lib, pkgs, ... }:

{
  environment.systemPackages = [ pkgs.cifs-utils ];

  fileSystems."/mnt/exodus/home" = {
    device = "//exodus/home";
    fsType = "cifs";
    options = let
      automount_opts = "x-systemd.automount,noauto,x-systemd.idle-timeout=60,x-systemd.device-timeout=5s,x-systemd.mount-timeout=5s,user,users";

      in [ "${automount_opts},credentials=/etc/nixos/secrets/exodus-smb,uid=1000,gid=100"];
  };
}
building Nix...
building the system configuration...
these 21 derivations will be built:
  /nix/store/7r2gqdwc4m6yykzghiz9j3d0jdwg5cjv-builder.pl.drv
  /nix/store/0lvfzbg89hw0jqnfcf74akjsv1v91jj7-system-path.drv
  /nix/store/xwyfb57kq26hs6qfq6vzcw51kksgpg80-X-Restart-Triggers-polkit.drv
  /nix/store/1b2s92ds0wlmfdin0fwk3drmvf9sd84x-unit-polkit.service.drv
  /nix/store/325mxgb9rxnqxwbgn7vmwa5263alc77q-stage-2-init.sh.drv
  /nix/store/3h9qx5v4yizr1v2bzk93s23bi0kbbbzb-unit-console-getty.service-disabled.drv
  /nix/store/6abhcq5xli5hifhvcy48ri5kidl8l28g-unit-pipewire.socket-disabled.drv
  /nix/store/g88b3xka6mj8nrinmix0knkyg2iv9yzs-boot.json.drv
  /nix/store/jymdhqg74rppc914dkx145i0l0gk376h-unit-pipewire.service-disabled.drv
  /nix/store/ngdvpzng82jsqjgpg6lrn5gkj13ls977-unit-wireplumber.service-disabled.drv
  /nix/store/m064pnwppdmyr5fg8npmwijblwvvpg8w-dbus-1.drv
  /nix/store/bz84di11ajwi2b53s67c9wd6rj6l1655-X-Restart-Triggers-dbus.drv
  /nix/store/v2z7vpgb8b48jxil49dv00iwj71320hj-unit-dbus.service.drv
  /nix/store/f8rc33v6a3l9kfqzik61bar2japr8zcf-system-units.drv
  /nix/store/ddmdc416m203mj1nwv0yw2dn7rs9smxj-unit-dbus.service.drv
  /nix/store/nh8nwy3mx6mnklc9rkh8zaj542751r0w-user-units.drv
  /nix/store/qija2zzribzivbby9syglffwwghc7br2-etc-fstab.drv
  /nix/store/n2m5j7m4l4wskv92gzvw026n1cv6djwn-etc.drv
  /nix/store/vwy0kr2da1q0g0f31ry2v14wdrlshyi4-perl-5.40.0-env.drv
  /nix/store/z26r9m07b4ddwpg2hiin7786hjln7glc-ensure-all-wrappers-paths-exist.drv
  /nix/store/bw7da85mraw5f1fz2vqhf2vls2scg3ap-nixos-system-andreas-ryzen-24.11.714685.36864ed72f23.drv
these 17 paths will be fetched (52.45 MiB download, 236.94 MiB unpacked):
  /nix/store/qlzvmgr8w9prdlyys7irqf86p7bndf5b-binutils-wrapper-2.43.1
  /nix/store/mxi53f9xhkshf3la64awqacfmx9ppkzw-die-hook
  /nix/store/4xpviqy8kghz7410p5aagdhykcjcpnd1-expand-response-params
  /nix/store/62qjb50708fdhb4f2y7zxyqr1afir4fk-gcc-13.3.0
  /nix/store/888bkaqdpfpx72dd8bdc69qsqlgbhcvf-gcc-wrapper-13.3.0
  /nix/store/amahni7fc4in6v9s0ph2pjgm5sj2nzpz-getconf-glibc-2.40-36
  /nix/store/kwq87k2nykp8fkw8jgqav4jl5nw65isv-gmp-6.3.0
  /nix/store/idpsjqf760ap2vr49hkdshhj8sfdc6mn-isl-0.20
  /nix/store/w75dbhs3yxq98309az0ybgrg2afq8g1p-libmpc-1.3.1
  /nix/store/33vsl4vhfqarbc7pdnp29p7gf7s10rcg-libxslt-1.1.42-bin
  /nix/store/sbr9bjn36i9ibh5hmdni1p3nrlbkm7qc-lndir-1.0.5
  /nix/store/vi2j2pqg0vcwrq9nv1lcxqr9czfbfza2-make-binary-wrapper-hook
  /nix/store/3ibs1c03k683g2vv2rii60476w690xs3-make-shell-wrapper-hook
  /nix/store/simak2bypwin0skwr4p9pbgccnyi1jph-mpfr-4.2.1
  /nix/store/jf2ym7brf074656hzz4whfpvrb2iack5-perl5.40.0-Config-IniFiles-3.000003
  /nix/store/3xnzi2psjmprk7lff1rmsfnbsrq18f9n-perl5.40.0-IO-Stringy-2.113
  /nix/store/0946srvdrjhrgdwxx5s1av1hds56i1n8-texinfo-7.1.1
copying path '/nix/store/mxi53f9xhkshf3la64awqacfmx9ppkzw-die-hook' from 'https://cache.nixos.org'...
copying path '/nix/store/3xnzi2psjmprk7lff1rmsfnbsrq18f9n-perl5.40.0-IO-Stringy-2.113' from 'https://cache.nixos.org'...
building '/nix/store/g88b3xka6mj8nrinmix0knkyg2iv9yzs-boot.json.drv'...
building '/nix/store/z26r9m07b4ddwpg2hiin7786hjln7glc-ensure-all-wrappers-paths-exist.drv'...
building '/nix/store/325mxgb9rxnqxwbgn7vmwa5263alc77q-stage-2-init.sh.drv'...
copying path '/nix/store/4xpviqy8kghz7410p5aagdhykcjcpnd1-expand-response-params' from 'https://cache.nixos.org'...
copying path '/nix/store/amahni7fc4in6v9s0ph2pjgm5sj2nzpz-getconf-glibc-2.40-36' from 'https://cache.nixos.org'...
copying path '/nix/store/0946srvdrjhrgdwxx5s1av1hds56i1n8-texinfo-7.1.1' from 'https://cache.nixos.org'...
building '/nix/store/7r2gqdwc4m6yykzghiz9j3d0jdwg5cjv-builder.pl.drv'...
building '/nix/store/qija2zzribzivbby9syglffwwghc7br2-etc-fstab.drv'...
copying path '/nix/store/33vsl4vhfqarbc7pdnp29p7gf7s10rcg-libxslt-1.1.42-bin' from 'https://cache.nixos.org'...
copying path '/nix/store/sbr9bjn36i9ibh5hmdni1p3nrlbkm7qc-lndir-1.0.5' from 'https://cache.nixos.org'...
building '/nix/store/3h9qx5v4yizr1v2bzk93s23bi0kbbbzb-unit-console-getty.service-disabled.drv'...
building '/nix/store/jymdhqg74rppc914dkx145i0l0gk376h-unit-pipewire.service-disabled.drv'...
building '/nix/store/6abhcq5xli5hifhvcy48ri5kidl8l28g-unit-pipewire.socket-disabled.drv'...
building '/nix/store/ngdvpzng82jsqjgpg6lrn5gkj13ls977-unit-wireplumber.service-disabled.drv'...
Checking that Nix store paths of all wrapped programs exist... OK
copying path '/nix/store/kwq87k2nykp8fkw8jgqav4jl5nw65isv-gmp-6.3.0' from 'https://cache.nixos.org'...
copying path '/nix/store/qlzvmgr8w9prdlyys7irqf86p7bndf5b-binutils-wrapper-2.43.1' from 'https://cache.nixos.org'...
copying path '/nix/store/3ibs1c03k683g2vv2rii60476w690xs3-make-shell-wrapper-hook' from 'https://cache.nixos.org'...
copying path '/nix/store/jf2ym7brf074656hzz4whfpvrb2iack5-perl5.40.0-Config-IniFiles-3.000003' from 'https://cache.nixos.org'...
building '/nix/store/0lvfzbg89hw0jqnfcf74akjsv1v91jj7-system-path.drv'...
copying path '/nix/store/idpsjqf760ap2vr49hkdshhj8sfdc6mn-isl-0.20' from 'https://cache.nixos.org'...
copying path '/nix/store/simak2bypwin0skwr4p9pbgccnyi1jph-mpfr-4.2.1' from 'https://cache.nixos.org'...
created 7599 symlinks in user environment
copying path '/nix/store/w75dbhs3yxq98309az0ybgrg2afq8g1p-libmpc-1.3.1' from 'https://cache.nixos.org'...
building '/nix/store/xwyfb57kq26hs6qfq6vzcw51kksgpg80-X-Restart-Triggers-polkit.drv'...
building '/nix/store/m064pnwppdmyr5fg8npmwijblwvvpg8w-dbus-1.drv'...
copying path '/nix/store/62qjb50708fdhb4f2y7zxyqr1afir4fk-gcc-13.3.0' from 'https://cache.nixos.org'...
building '/nix/store/1b2s92ds0wlmfdin0fwk3drmvf9sd84x-unit-polkit.service.drv'...
building '/nix/store/bz84di11ajwi2b53s67c9wd6rj6l1655-X-Restart-Triggers-dbus.drv'...
building '/nix/store/ddmdc416m203mj1nwv0yw2dn7rs9smxj-unit-dbus.service.drv'...
building '/nix/store/v2z7vpgb8b48jxil49dv00iwj71320hj-unit-dbus.service.drv'...
building '/nix/store/nh8nwy3mx6mnklc9rkh8zaj542751r0w-user-units.drv'...
building '/nix/store/f8rc33v6a3l9kfqzik61bar2japr8zcf-system-units.drv'...
building '/nix/store/n2m5j7m4l4wskv92gzvw026n1cv6djwn-etc.drv'...
copying path '/nix/store/888bkaqdpfpx72dd8bdc69qsqlgbhcvf-gcc-wrapper-13.3.0' from 'https://cache.nixos.org'...
copying path '/nix/store/vi2j2pqg0vcwrq9nv1lcxqr9czfbfza2-make-binary-wrapper-hook' from 'https://cache.nixos.org'...
building '/nix/store/vwy0kr2da1q0g0f31ry2v14wdrlshyi4-perl-5.40.0-env.drv'...
created 183 symlinks in user environment
building '/nix/store/bw7da85mraw5f1fz2vqhf2vls2scg3ap-nixos-system-andreas-ryzen-24.11.714685.36864ed72f23.drv'...
activating the configuration...
setting up /etc...
reloading user units for andreas...
restarting sysinit-reactivation.target
Error: Failed to open unit file /nix/store/32p82vxm2pa1hycq44041rivvndsh8wi-nixos-system-andreas-ryzen-24.11.714685.36864ed72f23/etc/systemd/system/mnt-exodus-home.mount

Caused by:
    No such file or directory (os error 2)
warning: error(s) occurred while switching to the new configuration

Even when uncommenting the module import in configuration.nix, the error persists. I have to reboot and boot an older configuration to get a usable system again (which is really awesome).

Can anybody help me here?

Thanks, Andreas