Commit Graph

2730 Commits

Author SHA1 Message Date
nikstur
e7b7271ffc
Merge pull request #336513 from nikstur/etc-overlay-fixes
etc.overlay fixes
2024-08-22 13:57:04 +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
Felix Stupp
4b998d179f
nixos/systemd.network: add support for UseDomains= in [Network] sections
Those options were also added with systemd 256, but sadly were missed out in #307068.

These options are documented in:
- [systemd 256 changelog](https://github.com/systemd/systemd/releases/tag/v256) (search for `UseDomains=`)
- [networkd.conf(5)](https://www.freedesktop.org/software/systemd/man/256/networkd.conf.html#UseDomains=)
- [systemd.network(5)](https://www.freedesktop.org/software/systemd/man/256/systemd.network.html#UseDomains=)
2024-08-21 19:48:29 +00:00
Florian Klink
cce9aef6fd
Merge pull request #334337 from eduarrrd/eaccess-null
nixos/systemd/initrd: Fix emergencyAccess to work with `null`.
2024-08-19 14:44:25 +03:00
nikstur
0a810476ad
Merge pull request #307528 from WilliButz/systemd-initrd/tmpfiles-settings
nixos/systemd-tmpfiles: add initrd support
2024-08-19 11:54:42 +02:00
Will Fancher
f84991dc2b
Merge pull request #334288 from ElvishJerricco/systemd-initrd-fully-merge-sbin
Systemd initrd fully merge sbin
2024-08-18 22:41:53 -04:00
Eduard Bachmakov
b33bf6b99a nixos/systemd/initrd: Fix emergencyAccess to work with null.
Implementation is now compatible with the option's .type already defined.

This allows us to pass `config.users.users.<user>.hashedPassword` even if this is null (the default).

Before:
true  => access
false => no access
hash  => access via password
null  => eval error

After:
true  => access
false => no access
hash  => access via password
null  => no access
2024-08-14 10:26:15 +02:00
Will Fancher
0637303ca8 Revert "Merge pull request #330017 from Mic92/boot-counting"
This reverts commit 3d3c0f4d34, reversing
changes made to 47f7e25a77.
2024-08-13 23:11:18 -04:00
Will Fancher
b78bd2f912 Revert "Merge pull request #333952 from r-vdp/specialisation-name-regex"
This reverts commit fc35704bc8, reversing
changes made to c67d90d517.
2024-08-13 21:33:15 -04:00
WilliButz
8dd369f524
nixos/systemd-tmpfiles: add initrd support
This adds support for declaring tmpfiles rules exclusively for the
systemd initrd. Configuration is possible through the new option
`boot.initrd.systemd.tmpfiles.settings` that shares the same interface as
`systemd.tmpfiles.settings`.

I did intentionally not replicate the `rules` interface here, given that
the settings attribute set is more versatile than the list of strings
used for `rules`. This should also make it unnecessary to implement the
workaround from 1a68e21d47 again.

A self-contained `tmpfiles.d` directory is generated from the new initrd
settings and it is added to the initrd as a content path at
`/etc/tmpfiles.d`.

The stage-1 `systemd-tmpfiles-setup.service` is now altered to no longer
operate under the `/sysroot` prefix, because the `/sysroot` hierarchy
cannot be expected to be available when the default upstream service is
started.

To handle files under `/sysroot` a slightly altered version of the
upstream default service is introduced. This new unit
`systemd-tmpfiles-setup-sysroot.service` operates only under the
`/sysroot` prefix and it is ordered between `initrd-fs.target` and the
nixos activation.

Config related to tmpfiles was moved from initrd.nix to tmpfiles.nix.
2024-08-13 13:02:21 +02:00
Will Fancher
208e953381 systemd-stage-1: Fully merge /bin and /sbin
In #327506, we stopped using `/sbin` in the `pathsToLink` of `initrdBinEnv`. This inadvertantly stopped including the `sbin` directory of the `initrdBin` packages, which meant that things like `mdadm`'s udev rules, which referred to binaries by their `sbin` paths, stopped working.

The purpose of #327506 was to fix the fact that `mount` was not calling mount helpers like `mount.ext4` unless they happened to be in `/sbin`. But this raised some questions for me, because I thought we set `managerEnvironment.PATH` to help util-linux find helpers for both `mount` and `fsck`. So I decided to look at how this works in stage 2 to figure it out, and it's a little cursed.

---

What I already knew is that we have [this](696a4e3758/nixos/modules/system/boot/systemd.nix (L624-L625))

```
        # util-linux is needed for the main fsck utility wrapping the fs-specific ones
        PATH = lib.makeBinPath (config.system.fsPackages ++ [cfg.package.util-linux]);
```

And I thought this was how `mount` finds the mount helpers. But if that were true, then `mount` should be finding helpers in stage 1 because of [this](696a4e3758/nixos/modules/system/boot/systemd/initrd.nix (L411))

```
      managerEnvironment.PATH = "/bin";
```

Turns out, `mount` _actually_ finds helpers with [this configure flag](696a4e3758/pkgs/os-specific/linux/util-linux/default.nix (L59))

```
    "--enable-fs-paths-default=/run/wrappers/bin:/run/current-system/sw/bin:/sbin"
```

Ok... so then why do we need the PATH? Because `fsck` has [this](a75c7a102e/disk-utils/fsck.c (L1659))

```
	fsck_path = xstrdup(path && *path ? path : FSCK_DEFAULT_PATH);
```

(`path` is `getenv("PATH")`)

So, tl;dr, `mount` and `fsck` have completely unrelated search paths for their helper programs

For `mount`, we have to use a configure flag to point to `/run/current-system`, and for `fsck` we can just set PATH

---

So, for systemd stage 1, we *do* want to include packages' `sbin` paths, because of the `mdadm` problem. But for `mount`, we need helpers to be on the search path, and right now that means putting it somewhere in `/run/wrappers/bin:/run/current-system/sw/bin:/sbin`.
2024-08-12 23:35:01 -04:00
Will Fancher
d74d182991 Revert "systemd-stage-1: Use common bin for /sbin"
This reverts commit b4b4751e97.
2024-08-12 23:35:01 -04:00
Will Fancher
bcd1d9cf54
Merge pull request #312755 from tomfitzhenry/systemd-dhcp108
nixos/networkd: allow IPv6OnlyPreferredSec in networkd.conf
2024-08-12 19:19:34 -04:00
Florian Klink
fc35704bc8
Merge pull request #333952 from r-vdp/specialisation-name-regex
specialisation: limit the allowed characters in specialisation names
2024-08-12 13:30:54 +03:00
r-vdp
d38257b024
systemd-boot-builder: allow underscores in the specialisation name 2024-08-11 23:33:18 +02:00
Pol Dellaiera
71daf1a037
Merge pull request #333643 from eduarrrd/initrd-ids
nixos/systemd/initrd: Set /etc/hostname in the initrd.
2024-08-11 20:32:20 +02:00
r-vdp
57a30e4cbd
specialisation: limit the allowed characters in specialisation names
Since the systemd boot counting PR was merged, dashes in specialisation
names cause issues when installing the boot loader entries, since dashes
are also used as separator for the different components of the file name
of the boot loader entries on disk.

The assertion avoids this footgun which is pretty annoying to recover
from.
2024-08-11 19:07:44 +02:00
Eduard Bachmakov
7cc66df3ec nixos/systemd/initrd: Set /etc/hostname in the initrd.
With the the Systemd-based initrd, systemd-journald is doing the logging.
One of Journald's Trusted Journal Fields is `_HOSTNAME` (systemd.journal-fields(7)).
Without explicitly setting the hostname via this file or the kernel cmdline, `localhost` is used and captured in the journal.
As a result, a boot's log references multiple hostnames.
With centralized log collection this breaks filtering (more so when logs from multiple Systemd-based initrds are streaming in simultaneously.

Fixes #318907.
2024-08-10 11:16:25 +02:00
nikstur
fa12935a32
Merge pull request #333006 from nikstur/static-mtab
nixos/systemd-tmpfiles: create /etc/mtab via environmemt.etc instead of tmpfiles
2024-08-08 12:00:07 +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
Franz Pletz
481d7272d1
Merge pull request #201202 from m-bdf/sdboot-infinite-timeout 2024-08-06 16:25:25 +02:00
Franz Pletz
97ebf11501
Merge pull request #319422 from jmbaur/systemd-boot-devicetree 2024-08-06 13:39:29 +02:00
Florian Klink
a9f1cb6e2f
Merge pull request #253260 from thblt/systemd-bitlocker
Create boot.loader.systemd-boot.rebootForBitlocker option
2024-08-05 17:03:13 +03:00
Florian Klink
a5265503e6
Merge pull request #327506 from ElvishJerricco/systemd-initrd-merge-sbin
systemd-stage-1: Use common bin for /sbin
2024-08-05 14:18:51 +03:00
Thibault Polge
a68b81c429 nixos/systemd-boot: Add reboot-for-bitlocker support
Windows with BitLocker and TPM enabled doesn't support boot chaining.
This option activates a special experimental mode in systemd-boot that
tries to detect such systems and, if detected and selected by the user
at the boot menu, set the BootNext EFI variable to it before resetting.
2024-08-05 13:17:25 +03:00
Maëlys Bras de fer
7ae6219163 nixos/systemd-boot: fix infinite timeout 2024-08-05 08:48:54 +00:00
František Hanzlík
8b4cd01f90
nixos/networkd: allow specifying FirewallMark mask 2024-08-01 22:22:01 +02:00
Jared Baur
fca8ee915d
nixos/systemd-boot: add support for devicetree entry
The [Boot Loader Specification](https://uapi-group.org/specifications/specs/boot_loader_specification/)
allows for using a key called "devicetree" for specifying which
devicetree the bootloader should use during boot. With regards to
systemd-boot, this key is used to specify which file should be picked up
from the ESP to install to the EFI DTB Configuration Table. Linux then uses
this Configuration Table to setup the machine. This change is similar to
the one done in https://github.com/NixOS/nixpkgs/pull/295096, where that
change was for adding DTB support to systemd-stub, and this is for
systemd-boot.
2024-08-01 11:15:15 -07:00
Arian van Putten
45e041902f nixos/systemd: drop support for legacy cgroup hierachy 2024-07-31 13:49:58 +02:00
Masum Reza
cb27644348
Merge pull request #310661 from somasis/boot.plymouth.font
nixos/boot.plymouth.font: escape font path
2024-07-31 00:39:11 +05:30
Vladimír Čunát
a5b2fe7374
Merge #328673: staging-next 2024-07-20 2024-07-28 13:45:55 +02:00
Robert Hensing
4ca52fdf5f
Merge pull request #323613 from CyberShadow/fix-nix-path-without-channels-v2
nix-channel: do not set empty nix-path when disabling channels
2024-07-28 13:31:10 +02:00
K900
24076029d2 Merge remote-tracking branch 'origin/master' into staging-next 2024-07-28 01:04:35 +03:00
Julien Malka
64edc7f00f nixos/systemd-boot: init boot counting
Update nixos/modules/system/boot/loader/systemd-boot/boot-counting.md

Co-authored-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
2024-07-26 20:04:37 +02:00
github-actions[bot]
2567b049bd
Merge master into staging-next 2024-07-25 18:00:59 +00:00
Anton Mosich
bc1c51d6d0
nixos/system: fix grammatical error in docs 2024-07-25 18:19:35 +02:00
Artturin
60e9cffe2c Merge branch 'master' into staging-next 2024-07-22 22:53:31 +03:00
nikstur
be0df72dfa
Merge pull request #328926 from nikstur/sysusers-only-for-sysusers
Sysusers only for sysusers
2024-07-22 20:55:58 +02:00
Marcus Ramberg
585a077fd2
Merge pull request #327665 from bolives-hax/add-qemu-s390x-binfmt
added s390x option type via magic attributes
2024-07-21 23:12:55 +02:00
bl0v3
e83fc89111 nixos/binfmt: added s390x option type via magic attributes 2024-07-21 20:17:16 +02:00
nikstur
2ca04530c9 nixos/systemd-sysusers: assert against password and hashedPassword
Regardless of mutable or immutable users, systemd-sysupdate never
updates existing user records and thus will for example never change
passwords for you.

It only support initial passwords and now actively asserts agains other
paswords.
2024-07-21 16:23:11 +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
d43e323b4a nixos/systemd-sysusers: only create systemusers
systemd-sysusers cannot create normal users (i.e. with a UID > 1000).
Thus we stop trying an explitily only use systemd-sysusers when there
are no normal users on the system (e.g. appliances).
2024-07-21 16:22:01 +02:00
Will Fancher
6f959a9e96 nixos/make-initrd-ng: dlopen ELF notes 2024-07-21 06:31:42 -04:00
Will Fancher
e6c544270c nixos/make-initrd-ng: Pass contents as JSON 2024-07-21 06:31:42 -04:00
nikstur
d4a80b6d0c systemd: 255.6 -> 256.2 2024-07-21 06:31:37 -04:00
Jörg Thalheim
054c2d71f7
Merge pull request #328221 from nikstur/fix-overlay-etc
nixos/etc: handle mountpoints on top of /etc when switching
2024-07-18 21:59:30 +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
Sandro
fa5abfe559
Merge pull request #317623 from jmbaur/stc-ng-followup 2024-07-18 11:33:59 +02:00