Commit Graph

33 Commits

Author SHA1 Message Date
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
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
Ramses
5d8dc420a0 nixos/etc: clear stale opaque markers from mutable overlay upperdir (#507963) 2026-05-13 16:36:09 +00:00
Lucas Savva
418a0ae8f9 switch-to-configuration-ng: Stop drop-in template instances
As the test shows, stc-ng previously did not correctly account for the
removal of template instances defined with overrideStrategy "asDropin".
A real use case does exist: Defining systemd-nspawn container units
which inherit the settings from the vendored systemd-nspawn@.service.

I tried to find the least intrusvie but stable solution here. The
globbing is technically unnecessary but it mimics the behaviour and
implementation in parse_unit.
2026-04-30 18:06:59 +02: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
07841512d2 nixos/tests/etc-overlay-mutable: add regression test for opaque upperdir
When a directory is created in /etc that does not yet exist in the
overlay's lowerdir, overlayfs marks it opaque in the upperdir. This is
correct at creation time, but becomes stale when a later generation
adds entries under that directory: the opaque marker hides them.

stage-2-init.sh runs `install -d /etc/nixos` on every boot. When
/nixos is absent from the metadata layer, /.rw-etc/upper/nixos becomes
opaque. Switching to a generation that adds environment.etc."nixos/*"
then silently fails to expose those entries in /etc.

Add a failing regression test that exercises both the
switch-to-configuration path and the initrd/boot path.

Reproduces #505475
2026-04-19 23:05:10 +02:00
nikstur
7f49ae6543 nixos/nixos-init: conflict with postBootCommands and powerUpCommands (#474454) 2026-01-08 22:36:36 +00:00
Majiir Paktu
e656d186b2 nixos/nixos-init: conflict with postBootCommands and powerUpCommands 2026-01-06 21:00:36 -05:00
r-vdp
6c5c3d85c7 nixos/etc-overlay: we can run the etc overlay tests with the default kernel now 2025-12-29 21:12:37 +02:00
nikstur
74c6c5d9bc nixos/etc-overlay: pad the mode when building the composefs dump (#464031) 2025-11-24 09:13:44 +00: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
Tom Herbers
c9dc62eda1 treewide: switch to channels.nixos.org
This is a follow-up for #460057 to completely remove all mentions of nixos.org/channels/.

The following command was used to generate this change:

```
find . -type f -exec sed -i 's|nixos.org/channels/|channels.nixos.org/|g' {} +
```
2025-11-17 23:41:39 +01:00
nikstur
653fd8c995 nixos/systemd/shutdown: make shutdown ramfs bashless 2025-10-14 10:14:43 +02:00
Emily
7f9a83be1f nixos/nixos-init: add more strict assertions for required config (#450775) 2025-10-12 15:15:13 +00:00
nikstur
8f5d10fd7e nixos/nixos-init: add more strict assertions for required config 2025-10-12 16:55:23 +02:00
nikstur
0e0be1398a nixos/profiles: add bashless profile 2025-10-09 23:52:39 +02:00
nikstur
d0c03e4c5a nixos-init: init at 0.1.0 2025-09-23 00:21:33 +02: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
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 a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00
r-vdp
65f375d172 etc: extend tests to ensure that temporary dirs are cleaned up 2024-10-16 22:24:46 +02:00
r-vdp
a4f7868edf nixos/etc-overlay: fix VM test for immutable overlay 2024-10-16 17:42: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
nikstur
9e720a5881 nixos/systemd-tmpfiles: create /etc/mtab via environmemt.etc instead of tmpfiles
This enables an immutable /etc via `system.etc.overlay.mutable = false`.
2024-08-07 16:12:37 +02:00
nikstur
2710a49adb nixos/systemd-sysusers: stop creating users statically
On Linux we cannot feasbibly generate users statically because we need
to take care to not change or re-use UIDs over the lifetime of a machine
(i.e. over multiple generations). This means we need the context of the
running machine.

Thus, stop creating users statically and instead generate them at
runtime irrespective of mutableUsers.

When /etc is immutable, the password files (e.g. /etc/passwd etc.) are
created in a separate directory (/var/lib/nixos/etc). /etc will be
pre-populated with symlinks to this separate directory.

Immutable users are now implemented by bind-mounting the password files
read-only onto themselves and only briefly re-mounting them writable to
re-execute sysusers. The biggest limitation of this design is that you
now need to manually unmount this bind mount to change passwords because
sysusers cannot change passwords for you. This shouldn't be too much of
an issue because system users should only rarely need to change their
passwords.
2024-07-21 16:23:11 +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
ivan770
1b288bca00 nixos/etc: support direct symlinks with etc overlay 2024-05-25 08:41:24 -04:00
nikstur
5df8caced4 nixos/etc: make re-mounting /etc overlay idempotent 2024-02-21 22:54:00 +01:00
nikstur
8710a27bc6 nixos/profiles/perlless: init 2024-01-22 00:54:13 +01:00
nikstur
60f529fc82 nixos/etc: optionally mount etc as an overlay 2024-01-22 00:54:13 +01:00
nikstur
7d0b5b3a94 nixos/nix-channnel: fix setting up the default channel again 2023-11-01 16:23:28 +01:00
nikstur
8c1739cafe nixos/nix-channel: fix subscribing to default channel
Fixes https://github.com/NixOS/nixpkgs/issues/264602
2023-10-31 16:51:23 +01:00
nikstur
cb08d3dd72 nixos/nix-channel: replace activationScript via tmpfiles 2023-10-25 23:43:58 +02:00
nikstur
59e3726755 nixos/activation: replace var activationScript via tmpfiles 2023-10-25 00:48:37 +02:00