Skip to content

nixos/etc: create uninitialized /etc/machine-id with readonly /etc/ - #523894

Merged
r-vdp merged 1 commit into
NixOS:masterfrom
anglesideangle:fix-immutable-etc
Jun 3, 2026
Merged

nixos/etc: create uninitialized /etc/machine-id with readonly /etc/#523894
r-vdp merged 1 commit into
NixOS:masterfrom
anglesideangle:fix-immutable-etc

Conversation

@anglesideangle

@anglesideangle anglesideangle commented May 25, 2026

Copy link
Copy Markdown
Contributor

This closes #523878 where /etc/ is readonly and /etc/machine-id cannot be created. This also fixes the activation-etc-overlay-immutable test, and likely others.

Things done

@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. 9.needs: reviewer This PR currently has no reviewers requested and needs attention. 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 May 25, 2026
@rebmit

rebmit commented May 25, 2026

Copy link
Copy Markdown
Member

IIUC, with this fix, systemd will generate a new transient /etc/machine-id on every boot, which in most cases will be different each time.

I think it would be preferable to symlink or bind-mount /etc/machine-id to a conventional mutable persistent location (maybe /var/lib/nixos/machine-id, like what we do for userborn), to preserve systemd first-boot semantics.

Ref: https://github.com/nix-community/preservation/pull/23/changes#diff-a7e9fed4bb5bc260fb810fc55ee5e78a8b5b0f153e8307b1b84f635fcd74598f

This resolves NixOS#523878 where /etc/ is readonly and /etc/machine-id
cannot be created. Instead, /etc/machine-id is initialized to
"uninitialized" by systemd-tmpfiles in initrd and persisted in
/var/lib/nixos.
@anglesideangle

Copy link
Copy Markdown
Contributor Author

Thanks for the reference to nix-community/preservation. I used the same approach with systemd-tmpfiles to initialize /var/lib/nixos/machine-id.

This is outside the scope of the PR, but perhaps it would be beneficial to bring something similar to the preservation library into core nixos?

@anglesideangle anglesideangle changed the title nixos/etc: create empty /etc/machine-id with readonly /etc/ nixos/etc: create uninitialized /etc/machine-id with readonly /etc/ May 30, 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/6993

@rebmit
rebmit requested review from Mic92, nikstur and r-vdp June 3, 2026 07:33
@nixpkgs-ci nixpkgs-ci Bot removed the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Jun 3, 2026
@r-vdp
r-vdp added this pull request to the merge queue Jun 3, 2026
Merged via the queue into NixOS:master with commit b431330 Jun 3, 2026
31 of 33 checks passed
@anglesideangle
anglesideangle deleted the fix-immutable-etc branch June 3, 2026 13:11
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: 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nixos/etc: no handling of /etc/machine-id with readonly /etc

4 participants