Initrd build Error: failed to copy "/nix/store/.../systemd" to "./root/nix/store/.../systemd"

The error:

$ sudo nixos-rebuild --impure --flake .#$HOSTNAME switch --show-trace       
building the system configuration...

error: Cannot build '/nix/store/c193hazsr5da4vz4zm2k2nqm46w5zkli-initrd-linux-6.18.49.drv'.
       Reason: builder failed with exit code 1.
       Output paths:
         /nix/store/zdbc3m1cg54v5jc8wg0jxnaf2y32r88n-initrd-linux-6.18.49

    ... full log redacted, see pastebin link below

      > Error: failed to copy "/nix/store/sm8d6jpilwdy3bw3yq2lv8rr8jld26pb-systemd-261.2/lib/systemd/systemd" to "./root/nix/store/sm8d6jpilwdy3bw3yq2lv8rr8jld26pb-systemd-261.2/lib/systemd/systemd"
       >
       > Caused by:
       >     Operation not permitted (os error 1)

The context:

  • I have a nixos config that works on many machines (home computer, laptop, server, WSL, etc.)
  • I tried to set up an “Erase your Darlings”-style ephemeral rootfs using ZFS on one of my machines, where the rootfs is rolled back using ZFS at boot (see https://github.com/michaelhaaf/nix-config/blob/9abcc6601fb3e3362890041bd6dfd39ead8c7b9d/hosts/nixos/home/default.nix#L135-L157 for the relevant config
  • This resulted in an arcane nixos bug on that machine, where both my primary user and the root user passwords were set to ! in /etc/shadow, effectively rendering it impossible to log in (see https://github.com/NixOS/nixpkgs/issues/208766 )
  • I couldn’t figure out a way around it: I reinstalled NixOS from a version 25.11 USB stick I had
  • Now, applying my config to that machine again (with the ZFS rollback startup script commented out), I get the error above.

My questions:

  • I haven’t found this error online, any guesses as to what’s going on?
  • What is the ./root folder named in the error – and why is a /nix/store being built under it?

The linked bug was fixed years ago, so it’s not literally the same issue, even if the symptom looks similar…

I presume it’s the template for the initrd, which has a reduced nix store built inside it since everything in nixos is built to run out of the nix store.

The linked bug was fixed years ago, so it’s not literally the same issue, even if the symptom looks similar…

Indeed… in my case, it’s also different in that it’s both root AND my primary user whose passwords were affected. I also (naively) attempted the same fix from that issue (setting initialHashedPassword to null), which did not work. I would like to investigate further what’s different about my case (I suspect user error on my part) but for the time being I have this other initrd issue.

I presume it’s the template for the initrd, which has a reduced nix store built inside it since everything in nixos is built to run out of the nix store.

Thank you: this has made something click for me to try next. I was looking around in the Nix manual and I’m now thinking that the build derivation should have env variables so I can see which folder is being used to build initrd, and double check the permissions to see if there’s anything strange happening (Building - Nix 2.35.2 Reference Manual)