Skip to content

nixos/stage-2: add x-initrd.mount to nixStoreMountOpts - #560805

Merged
nikstur merged 1 commit into
NixOS:staging-nixosfrom
nikstur:correctly-remount-nix-store
Sep 11, 2026
Merged

nikstur merged 1 commit into
NixOS:staging-nixosfrom
nikstur:correctly-remount-nix-store

Conversation

@nikstur

@nikstur nikstur commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Adding the x-initrd.mount flag here ensures that systemd keeps this
mount around until the very end of the shutdown procedure and thus
avoids the error message that it was unable to unmount the Nix Store.

This was first reported here: NixOS/nixos#126

We always carried a patch to systemd to avoid this message.
The patch 0001-Don-t-try-to-unmount-nix-or-nix-store.patch becomes
unnecessary with this commit and can be removed.

Things done

Adding the x-initrd.mount flag here ensures that systemd keeps this
mount around until the very end of the shutdown procedure and thus
avoids the error message that it was unable to unmount the Nix Store.

This was first reported here: NixOS/nixos#126

We always carried a patch to systemd to avoid this message.#
The patch 0001-Don-t-try-to-unmount-nix-or-nix-store.patch becomes
unnecessary with this commit and can be removed.
@nikstur
nikstur requested a review from a team September 7, 2026 08:39
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Sep 7, 2026
@nixpkgs-ci nixpkgs-ci Bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Sep 11, 2026
@GrimmTheShrimp

Copy link
Copy Markdown
Contributor

Hold on, does this actually work? I understand nixStoreMountOpts are used for a bind mount only. Does that properly protect the underlying mount of a disk?

@nikstur

nikstur commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Hold on, does this actually work? I understand nixStoreMountOpts are used for a bind mount only. Does that properly protect the underlying mount of a disk?

The only reason we still got this warning from systemd about being unable to properly unmount the disk is because we remount /nix/store without x-initrd.mount in the activation script/nixos-init. The underlying disk is always "protected" with x-initrd.mount because our fileSystems attr always adds it for /nix/store and /.

@nikstur
nikstur added this pull request to the merge queue Sep 11, 2026
Merged via the queue into NixOS:staging-nixos with commit 74068d0 Sep 11, 2026
36 of 38 checks passed
@nikstur
nikstur deleted the correctly-remount-nix-store branch September 11, 2026 11:34
@GrimmTheShrimp GrimmTheShrimp mentioned this pull request Sep 13, 2026
4 of 13 tasks
@ElvishJerricco

ElvishJerricco commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

The patch 0001-Don-t-try-to-unmount-nix-or-nix-store.patch becomes unnecessary with this commit and can be removed.

Unfortunately I don't think this is true, @nikstur. The x-initrd.mount option only prevents the mount from being stopped on the way to umount.target (x-initrd.mount is one of the things that makes a mount "extrinsic"). But systemd-shutdown still goes on an unmounting spree before pivoting to exitrd, which uses a different check, and that's what this patch still defends us against. It's necessary to keep /nix/store mounted at this point for the same reason that it's necessary to keep /usr mounted at this point, i.e. the host binaries should still function until the actual pivot to the exitrd, and the exitrd (or kernel in the absence of exitrd) can handle final unmounting.

I tried to argue upstream that anything mounted in initrd should only be unmounted in exitrd by default, but this notion was rejected: systemd/systemd#38767

nikstur added a commit to nikstur/nixpkgs that referenced this pull request Sep 15, 2026
- Removed 0001-Don-t-try-to-unmount-nix-or-nix-store.patch because we
  fixed it in NixOS with NixOS#560805
- Removed 0003-add-rootprefix-to-lookup-dir-paths.patch because we fixed
  it in NixOS with NixOS#559314
- Removed 0006-timesyncd-disable-NSCD-when-DNSSEC-validation-is-dis.patch
  because it was fixed upstream by
  systemd/systemd#43380
@nikstur

nikstur commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Unfortunately I don't think this is true, @nikstur. The x-initrd.mount option only prevents the mount from being stopped on the way to umount.target (x-initrd.mount is one of the things that makes a mount "extrinsic"). But systemd-shutdown still goes on an unmounting spree before pivoting to exitrd, which uses a different check, and that's what this patch still defends us against. It's necessary to keep /nix/store mounted at this point for the same reason that it's necessary to keep /usr mounted at this point, i.e. the host binaries should still function until the actual pivot to the exitrd, and the exitrd (or kernel in the absence of exitrd) can handle final unmounting.

I look at it this way:

  • We had some observable behaviour we didn't like (error messages when shutting down about not being able to unmount /nix/store)
  • We patched systemd to get rid of this error message.
  • If we set the x-initrd.mount flag, this observable behaviour stops (this is also what Poettering suggested), i.e. we fixed the reason why we created the patch.
  • Thus we should remove the patch.

When I removed the patch and set x-initrd.mount, all our systemd tests pass (including the shutdown test). So I don't see a reason to keep the patch around even if it might in theory be more "correct".

@ElvishJerricco

Copy link
Copy Markdown
Contributor

uh, because it will literally completely break shutdown scripts? The umount loop happens before shutdown scripts are run. Removing this patch is going to break a supported systemd feature.

I agree with the aversion to patches in general, but I'm sorry, this is too far. "I only care that the error message in our tests goes away, not if it's correct" is a completely ridiculous extent to take this to, @nikstur.

@nikstur

nikstur commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Removing this patch is going to break a supported systemd feature.

Our shutdown test in nixosTests.systemd keeps working so I cannot verify this claim. Please check the test and confirm that it indeed tests the shutdown and if not we need to change the test to actually test this feature.

. "I only care that the error message in our tests goes away, not if it's correct" is a completely ridiculous extent to take this to, @nikstur.

This is not what I said. I said I care about observable behavior and I cannot observe shutdown scripts not working.

@ElvishJerricco

Copy link
Copy Markdown
Contributor

My apologies for the harshness. I'll add a test.

nikstur added a commit to nikstur/nixpkgs that referenced this pull request Sep 17, 2026
- Removed 0001-Don-t-try-to-unmount-nix-or-nix-store.patch because we
  fixed it in NixOS with NixOS#560805
- Removed 0003-add-rootprefix-to-lookup-dir-paths.patch because we fixed
  it in NixOS with NixOS#559314
- Removed 0006-timesyncd-disable-NSCD-when-DNSSEC-validation-is-dis.patch
  because it was fixed upstream by
  systemd/systemd#43380
@ElvishJerricco

Copy link
Copy Markdown
Contributor

@nikstur This test fails without 0001-Don-t-try-to-unmount-nix-or-nix-store.patch #565136

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants