97 Commits
Author SHA1 Message Date
r-vdp 86a665d5b6 nixos/etc-overlay: fix machine-id-commit on first-boot when /etc is RO
The upstream unit has ConditionPathIsReadWrite=/etc, which is always
false on the read-only overlay, so the previous commit alone requires
users that want persistence to override the conditions themselves before
the generated ID can be written back.

Use ConditionFirstBoot instead, with the empty placeholder
first-boot is "no" and commit stays skipped, but when a writable
file containing "uninitialized" is bind-mounted over /etc/machine-id,
first-boot is "yes" once and commit writes the ID through the bind.
2026-06-26 10:50:58 +02:00
r-vdp 3eaafe4d48 nixos/etc-overlay: ship empty /etc/machine-id on immutable /etc
The symlink to /var/lib/nixos/machine-id never persists the ID,
systemd-machine-id-commit.service requires a writable /etc, and
machine_id_commit() does not follow symlinks for its mountpoint check.
So the backing file stays "uninitialized", every boot is
ConditionFirstBoot=yes, and the machine-id is random per boot.

Ship an empty regular file instead, systemd then overlays /run/machine-id
for the session, ConditionFirstBoot is correctly "no", commit is
cleanly condition-skipped, and the file is a usable bind target for
users that want persistence.

Fixes #523878
2026-06-26 10:50:57 +02:00
nixpkgs-ci[bot]andGitHub 42814ad4b8 Merge master into staging-next 2026-06-25 18:46:06 +00:00
Florian KlinkandGitHub 68439b2129 nixos/etc: inline small regular files into the etc-overlay metadata image (#510323) 2026-06-25 13:20:50 +00:00
Vladimír Čunát 105327541b Reapply "staging-nixos merge for 2026-06-19" (#534864)
This reverts commit 532f984da0, reversing
changes made to 421ceaeef8.
2026-06-24 12:17:06 +02:00
Vladimír ČunátandGitHub 6e628a4f79 Revert "staging-nixos merge for 2026-06-19" 2026-06-24 10:55:53 +02:00
Ilan Joselevich f61ff68f63 nixos-init: skip the etc overlay for a non-NixOS init=
find-etc verified the init= was inside a NixOS toplevel and bailed otherwise,
failing initrd-find-etc.service. The etc-overlay mounts require it, so for a
non-NixOS init= (e.g. init=/bin/sh) the initrd dropped to emergency mode before
initrd-init could switch-root into the target.

Make find-etc skip silently for a non-NixOS init=, leaving the /etc-basedir and
/etc-metadata-image symlinks uncreated, and gate the etc-metadata mount, the
/sysroot/etc overlay and the rw-etc service on those symlinks with
ConditionPathExists so they skip instead of fail. initrd-init then switch-roots
into the non-NixOS init directly. The NixOS path is unchanged: the symlinks
exist, so the conditions hold.

Extend the systemd-initrd-non-nixos test with a second node enabling
system.nixos-init.enable, so both the bash initrd-nixos-activation path and the
nixos-init path are covered.

Assisted-by: Claude:claude-opus-4-8
2026-06-16 17:32:17 +03:00
r-vdp b2f185c25b nixos/etc: inline small regular files into the metadata erofs image
Regular (non-symlink) /etc entries with an explicit mode are currently
written to the metadata erofs image as stubs that redirect to a
separate basedir layer. Every open() of such a file makes overlayfs open
two real files (the metadata stub and the basedir target).

composefs-dump supports embedding file content directly via the CONTENT
field (raw size limit LCFS_INLINE_CONTENT_MAX = 5000 bytes). Use it for
files up to 4096 bytes so they are served straight from erofs with a
single underlying open. Files above the threshold keep the existing basedir
redirect.

Basedir entries that are provably inlineable are filtered at eval time
(text-backed entries) so changing a small /etc file no longer rebuilds
etc-lowerdir. Other entries are filtered at build time using the
same size check as the dump generator.

On a minimal config the basedir becomes empty and an open+read+close of
/etc/sudoers drops from ~46k to ~12k kernel instructions (-73%).
The metadata image size is unchanged (content fits in erofs block slack).
2026-05-31 23:46:03 +03:00
Asa Paparo 6e5b63357b nixos/etc: create uninitialized /etc/machine-id with readonly /etc/
This resolves #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.
2026-05-30 16:52:46 -05:00
niksturandGitHub 6f0967e095 nixos/etc-overlay: replace pkgs.move-mount-beneath with mount, move-mount-beneath: drop (#515304) 2026-05-19 08:34:09 +00:00
Lương Việt Hoàng 35fb2e4ac0 nixos/etc-overlay: replace pkgs.move-mount-beneath with mount
As of util-linux v2.42, we can use `mount` to move mounts beneath.
2026-05-07 21:33:09 +07:00
r-vdp 1c7c4d2291 nixos/etc: clear stale opaque markers from mutable overlay upperdir
Fix by walking the newly-mounted metadata layer before the overlay is
(re)mounted and removing trusted.overlay.opaque from any upperdir
directory that now has a counterpart in the lowerdir. This turns those
directories back into merged views: user-placed files and individual
whiteouts are preserved, only the blanket hiding of lowerdir content
is undone.

Applied in both the activation script (switch-to-configuration) and
the initrd rw-etc service (boot), since the upperdir persists across
reboots. Uses the new clear-etc-opaque entrypoint of nixos-init so the
initrd stays bash-free.

Fixes #505475
2026-04-23 11:51:39 +02:00
r-vdp 1a0f9e6b04 nixos/etc-overlay: remove outdated comment (findmnt works as advertised) 2025-11-24 23:55:59 -03:00
r-vdp fc3e644e4f nixos/etc-overlay: fix shellcheck issues in activation script 2025-11-24 23:55:34 -03:00
r-vdp 01aacd04f8 nixos/etc-overlay: pad the mode when building the composefs dump
Fixes https://github.com/NixOS/nixpkgs/issues/462972
2025-11-22 20:49:09 -03:00
nikstur d9e6299acc nixos/etc: use nixos-init to find etc 2025-09-23 00:21:33 +02:00
Wolfgang Walther 5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
Jörg Thalheim 51ecd58047 system.etc.overlay: build erofs also locally
images in etc tends to be small in size (mostly contains symlinks)
so it's not worth it to reach out to a remote builder for that.
2025-05-30 18:52:30 +02:00
isabelandGitHub 00b6b1ffcc nixos/etc-overlay: mark EROFS_FS kernel configuration option as required (#365450) 2025-05-29 09:42:43 +01:00
niksturandGitHub 3f4a4ffa18 nixos/etc-overlay: mount etc with nodev,nosuid (#406397) 2025-05-17 20:32:38 +02:00
r-vdp a2f3516c24 nixos/etc-overlay: mount etc with nodev,nosuid 2025-05-12 10:35:18 +02:00
Sandro Jäckel 484b00be20 nixos/etc: remove rogue continue 2025-04-19 03:01:40 +02:00
Silvan Mosberger 374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](https://github.com/NixOS/nixpkgs/tree/8616af08d915377bd930395f3b700a0e93d08728/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
nikstur 2442d7afa9 nioxs/etc: improve docs for file ownership 2025-02-01 22:37:46 +01:00
github-actions[bot]andGitHub 44e4abfaf6 Merge master into staging-next 2025-01-14 18:04:33 +00:00
r-vdp e5b0c411a4 nixos/etc-overlay: fix chmod call in activation script
Fixes #373691
2025-01-14 13:55:35 +01:00
github-actions[bot]andGitHub 507f7fe91e Merge master into staging-next 2025-01-12 12:05:15 +00:00
RamsesandGitHub d24ca4701f nixos/etc-overlay: make the etc overlay compatible with nixos-enter and nixos-install (#364239) 2025-01-12 09:05:57 +01:00
github-actions[bot]andGitHub 3588b4d239 Merge staging-next into staging 2024-12-31 18:04:49 +00:00
Wolfgang Walther 255012c708 nixosTests.etc: fix with structuredAttrs
The NIX_ATTRS_SH_FILE needs to be available visible inside the
fakechroot environment, so that we can load it for structuredAttrs
support.
2024-12-29 18:36:48 +01:00
r-vdp df7c405f32 nixos/etc-overlay: always create the metadata mountpoints in /run
This avoids the dependence on the presence of /tmp, which causes issues
with nixos-install
2024-12-17 00:18:43 +01:00
r-vdp 2187d1970e nixos/etc-overlay: make the etc overlay compatible with nixos-enter and nixos-install
When using nixos-enter (and so also nixos-install) on a system with etc-overlay enabled,
he activation script gets called directly, and there is no systemd running.
This violates a couple of assumptions in the etc-overlay activation script which
assumed that it only ever ran when switching into a new generation and that
the very first /etc would always have been set up by the systemd initrd.

As more and more things are being moved into systemd components (initrd services,
mount units, tmpfiles, etc), I think that it is going to become increasingly
difficult to stay compatible with these tools, but at least for now there is
no real alternative and so we probably want to be able to install systems
with etc-overlay enabled.
2024-12-17 00:18:43 +01:00
andre4ik3 250359a4d5 nixos/etc-overlay: mark EROFS_FS kernel configuration option as required 2024-12-16 02:20:02 +04:00
Moritz Sanft bf2f6de39d nixos/etc-activation: only assert for 6.6 kernel in switchable systems
The assertion is based on the availability of `move-mount-beneath`, which is only used in re-activation logic for switchable systems. Systems that have `system.switch.enable == false` should be allowed to user older kernels.
2024-12-13 12:13:34 +01:00
Silvan Mosberger 667d42c00d treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build https://github.com/infinisil/treewide-nixpkgs-reformat-script/archive/a08b3a4d199c6124ac5b36a889d9099b4383463f.tar.gz \
      --argstr baseRev 57b193d8dd
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:27:17 +01:00
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build https://github.com/infinisil/treewide-nixpkgs-reformat-script/archive/a08b3a4d199c6124ac5b36a889d9099b4383463f.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00
r-vdp 7d6602e7de etc-overlay: mount the metadata image read-only
On recent kernels (> 6.12 ?) we get the following warning otherwise:
`mount: /tmp/nixos-etc-metadata.aHpRhO5sC4: WARNING: source write-protected, mounted read-only.`
2024-12-01 13:44:55 +01:00
Will Fancher f065a81ab4 nixos/systemd-stage-1: Use chroot-realpath 2024-11-11 05:52:18 -05:00
r-vdp 0f786baf5d etc: remove unneeded temporary directions after putting in place the new etc 2024-10-16 22:22:58 +02:00
r-vdp a2d4cea96e etc: rename the temporary dirs so that they are recognisable
This makes it a lot easier to understand which dir is which
2024-10-16 22:22:58 +02:00
r-vdp 24bf6e9cb8 nixos/etc-overlay: avoid rebuilding the initrd every time the etc contents change
Before this change, the hash of the etc metadata image was included in
the mount unit that's responsible for mounting this metadata image in the
initrd.
And because this metadata image changes with every change to the etc
contents, the initrd would be rebuild every time as well.
This can lead to a lot of rebuilds (especially when revision info is
included in /etc/os-release) and all these initrd archives use up a lot of
space on the ESP.

With this change, we instead include a symlink to the metadata image in the
top-level directory, in the same way as we already do for things like init and
prepare-root, and we deduce the store path from the init= kernel parameter,
in the same way as we already do to find the path to init and prepare-root.

Doing so avoids rebuilding the initrd all the time.
2024-10-16 17:42:58 +02:00
Jörg ThalheimandGitHub 15f80d9120 Improve assertions for etc.overlay and systemd-sysusers (#332516) 2024-09-23 17:01:30 +02:00
Philip TaronandGitHub 9916dc8728 treewide/nixos: remove with lib; part 2 (#335618) 2024-08-30 15:56:57 -07:00
Felix Buehler 10e8c2cecd nixos/environment.etc: remove with lib; 2024-08-30 23:01:45 +02:00
nikstur 4620067d79 nixos/userborn: init 2024-08-26 12:45:33 +02:00
nikstur 7845b89e24 nixos/etc: unmount old /etc hierarchy lazily
This should fix errors where /etc is reported to be busy and thus cannot
be unmounted.

Another solution we can consider if this doesn't work out as we expect
is to forcefully unmount /etc.
2024-08-22 12:17:20 +02:00
nikstur d820fe987e nixos/etc: wantedBy -> requiredBy for mounting overlay etc
I've observed that sometimes the overlay mount unit does not get started
when using wantedBy. requiredBy makes this relationship stricter and if
necessary will restart the initrd-fs.target and thus ensure that when
this target is reached /etc has alredy been mounted. This is in line
with the description of initrd-fs.target in systemd.special:

> Thus, once this target is reached the /sysroot/ hierarchy is fully set up
2024-08-22 12:12:18 +02:00
nikstur b87850d1d5 nixos/etc: remove assertion 2024-08-02 15:02:59 +02:00
nikstur 6abbe725ca nixos/etc: handle mountpoints on top of /etc when switching
The activation script that remounts the /etc overlay now handles other
mount points on top of /etc by bind mounting them to the new temporary
/etc overlay and then atomically revealing it.
2024-07-18 21:28:53 +02:00
Jared Baur 560cd874a3 nixos/etc: fix using etc overlay on cross-compiled systems
We need to run tooling from the build platform when generating the EROFS.
2024-06-26 19:50:24 -07:00