Skip to content

nixos/etc: avoid copying up existing file bind mount targets - #576316

Open
merrkry wants to merge 1 commit into
NixOS:masterfrom
merrkry:fix/etc-bind-mount-copy-up-upstream-20261020
Open

merrkry wants to merge 1 commit into
NixOS:masterfrom
merrkry:fix/etc-bind-mount-copy-up-upstream-20261020

Conversation

@merrkry

@merrkry merrkry commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

During a mutable /etc overlay switch, activation calls touch on file bind mount targets even when they already exist in the new lower layer (code).

The touch results in a timestamp update, which triggers overlayfs copy-up. The copied-up file persists in the upperdir with an origin handle that refers to that generation's lower inode.

We should create the target only when it is missing to avoid this unnecessary copy-up (updated code).

The regression test declares an empty regular file in the base configuration, so the lowerdir provides it in all three generations. It bind-mounts a regular file containing preserved over /etc/declared-filemount.

On switch, -f "$mountPoint" sees the regular bind-mounted source and returns true. Before transferring that mount, the old code touches $tmpMountPoint, which still exposes the empty file from the new lowerdir. This creates the unwanted upperdir copy.

After each of two generation switches, the test checks:

  • Reading /etc/declared-filemount returns preserved, confirming that the bind mount was transferred.
  • /.rw-etc/upper/declared-filemount does not exist, confirming that activation did not copy up the lowerdir placeholder.

The first switch is enough to reproduce the bug; the second checks the same properties along the existing test's next switch. The original file-mount case binds /dev/null, a character device. Its -f check returns false, so it skips the touch branch and does not cover this bug.

Related to #533343 (mount-point handling) and #437424. This fix is a small change and can be applied independently of the overlay switch rewrite.

Validation on x86_64-linux:

  • Without the fix, the new assertion fails after the first switch because the target exists in the upperdir.
  • With the fix, the full mutable overlay VM test passes, including both switches and reboot.
  • nixfmt --check on both changed files and git diff --check pass.
nix-build nixos/release.nix -A tests.activation-etc-overlay-mutable.x86_64-linux --no-out-link --max-jobs 2 --cores 2

AI disclosure: Codex with OpenAI GPT-6.1-Sol assisted with the code, regression test, commit message, and PR description. Validation used the NixOS VM test framework and nixfmt.

Things done

Activation touches file bind mount targets even when they already exist
in the new lower layer. This copies them into the persistent upperdir
with origin handles that refer to that generation's metadata image.

Only create missing targets. Extend the mutable overlay VM test to check
that a bind mount over a declared regular file survives two generation
switches without copying its target into the upperdir.

Assisted-by: Codex (OpenAI GPT-6.1-Sol)
@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: 0 This PR does not cause any packages to rebuild on Darwin. llm-assisted Contributions that include code generation with LLMs 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 Oct 20, 2026
@merrkry
merrkry marked this pull request as ready for review October 20, 2026 10:13
@nixpkgs-ci nixpkgs-ci Bot added 9.needs: reviewer This PR currently has no reviewers requested and needs attention. 7.no default reviewers This PR targets a package or module with no existing maintainers; roving reviewers, take pity! labels Oct 20, 2026
@nixos-discourse

Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/7838

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 7.no default reviewers This PR targets a package or module with no existing maintainers; roving reviewers, take pity! 8.has: module (update) This PR changes an existing module in `nixos/` 9.needs: reviewer This PR currently has no reviewers requested and needs attention. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. llm-assisted Contributions that include code generation with LLMs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants