Commit graph

353 commits

Author SHA1 Message Date
Will Fancher 0a53886700
nixos/{tmpfiles, wrappers}: explicitly set RestrictSUIDSGID false (#426882) 2025-07-30 04:31:21 -04:00
Grimmauld 5bc2d42ba9
nixos/systemd: make boot.initrd.systemd.managerEnvironment affect boot.initrd.systemd.settings.Manager 2025-07-28 11:24:33 +02:00
Grimmauld 071ce0b44a
nixos/systemd: remove boot.initrd.systemd.extraConfig 2025-07-28 11:24:29 +02:00
Grimmauld f0b71eebdc
nixos/systemd: add boot.initrd.systemd.settings.Manager option 2025-07-28 11:24:06 +02:00
Wolfgang Walther 5a0711127c
treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
Grimmauld 248c463f69
nixos/tmpfiles: explicitly set RestrictSUIDSGID = false
This ensures the tmpfiles resetup service has permissions
to create suid/sgid files, even if `DefaultRestrictSUIDSGID`
is set in system.conf. This is required, as tmpfiles
are used to e.g. set file permissions on the journal
directory.`DefaultRestrictSUIDSGID` is a new feature
coming in systemd 258 [1].

[1] https://github.com/systemd/systemd/pull/38126
2025-07-20 12:40:26 +02:00
nikstur 3fd41447c7
nixos/systemd/repart: add extraArgs option and Encrypt=tpm2 test (#422511) 2025-07-18 16:52:18 +02:00
phaer dd88db29ed modules/systemd-oomd: add After=systemd-sysusers.service
Before this change, systemd-oomd startup was flaky at least with
either systemd-sysusers or userborn enabled. It would restart several
times until users were provisioned, so that it finally succeeded.

An alternative would be to use a DynamicUser which was my first
approach, before I discovered that upstream added the after statement
in Dec 2024[1]. DynamicUsers could have further
implications (sandboxing, etc), so we follow upstream here.

It's not clear to me we why Upstreams "After=systemd-sysusers.service"
doesn't show up on nixos-unstable systems (systemd v257.6).

Userborn is covered, as its unit is aliased to systemd-sysusers.service.

The following test succeeded after this change on x86_64-linux:

  nix-build -A nixosTests.systemd-oomd

[1]: 36dd429680
2025-07-11 15:13:25 +02:00
Florian Klink e47cbf3942 nixos/systemd/repart: add extraArgs option
There's lots of options regarding dm-crypt, dm-verity and TPMs.
Creating individual NixOS options for all of them would be infeasible.
2025-07-04 23:15:23 +03:00
Bogdan-Cristian Tătăroiu 3332613add nixos/systemd-initrd: Fix fsck.xfs failing due to missing sh
When running with a xfs root partition and using systemd for stage 1
initrd, I noticed in journalctl that fsck.xfs always failed to execute.

The issue is that it is trying to use the below sh interpreter:

`#!/nix/store/xy4jjgw87sbgwylm5kn047d9gkbhsr9x-bash-5.2p37/bin/sh -f`

but the file does not exist in the initrd image.

/nix/store/xy4jjgw87sbgwylm5kn047d9gkbhsr9x-bash-5.2p37/bin/**bash**
exists since it gets pulled in by some package, but the rest of the
directory is not being pulled in.

boot/systemd/initrd.nix mentions that xfs_progs references the sh
interpreter and seems to explicitly try to address this by adding
${pkgs.bash}/bin to storePaths, but that's the wrong bash package.

Update the `storePaths` value to pull in `pkgs.bashNonInteractive`
rather than `pkgs.bash`.
2025-06-28 14:50:51 +01:00
r-vdp c28b3143da
nixos/systemd-oomd: use the correct name for the top-level user slice
`user-.slice` does not seem to exist, and the config we generate for it is
rejected by systemd (see `systemctl status user-.slice`).
I suppose that what was really intended here, was to configure
`user.slice`, which is the one that is documented in `man systemd.special`.

Reported-by: Ian Sollars <Ian.Sollars@brussels.msf.org>
2025-06-20 18:53:16 +02:00
nixpkgs-ci[bot] bc2e6e0ae4
Merge master into staging-next 2025-05-29 18:05:35 +00:00
Florian Klink 9dd801dea7
nixos/systemd-initrd: honor the enable option in contents (#411800) 2025-05-29 18:06:12 +03:00
nixpkgs-ci[bot] 96ecef502b
Merge master into staging-next 2025-05-29 12:06:54 +00:00
Fiona Behrens 99da5ec2bc nixos/systemd-initrd: honor the enable option in contents
The enable attribute of `boot.initrd.systemd.contents.<name>` was
ignored for building initrd storePaths. This resulted in building
derivations for the initrd even if it was disabled.

Found while testing a to build a nixos system with a kernel without
lodable modules[0]

[0]: https://github.com/NixOS/nixpkgs/pull/411792
2025-05-28 17:10:02 +00:00
Peter Marshall 7d36daa76a
nixos/systemd-stage-1: follow systemd /run propagation
We currently bypass systemd's switch-root logic by premounting
/sysroot/run. Make sure to propagate its sub-mounts with the recursive
flag, in accordance with the default switch-root logic.

This is required for creds at /run/credentials to survive the transition
from initrd -> host.
2025-05-28 13:02:39 -04:00
nixpkgs-ci[bot] cc7ffdded8
Merge master into staging-next 2025-05-26 18:05:25 +00:00
Jörg Thalheim 131462b962
emergencyMode, emergencyAccess: cross reference options in docs. (#410418) 2025-05-26 14:12:41 +02:00
DavHau d5d323a907 emergencyMode, emergencyAccess: cross reference options in docs.
I was confused why I could not get an emergency access console despite setting systemd.emergencyMode=true.

Turns out there is another similar option `boot.initrd.systemd.emergencyAccess` that I should have used.

This is confusing and this change should make it more clear vie the docs of both these options.
2025-05-24 14:01:22 +07:00
nixpkgs-ci[bot] 7ac4ee7b2a
Merge master into staging-next 2025-05-20 18:05:35 +00:00
benaryorg e434130d0b
nixos/systemd: unconditional systemd-journald-audit.socket
Containers did not have *systemd-journald-audit.socket* in *additionalUpstreamSystemUnits*, which meant that the unit was not provided.
However the *wantedBy* was added without any additional check, therefore creating an empty unit with just the *WantedBy* on *boot.isContainer* machines.
This caused `systemd-analyze verify` to fail:

```text
systemd-journald-audit.socket: Unit has no Listen setting (ListenStream=, ListenDatagram=, ListenFIFO=, ...). Refusing.
systemd-journald-audit.socket: Cannot add dependency job, ignoring: Unit systemd-journald-audit.socket has a bad unit file setting.
systemd-journald-audit.socket: Cannot add dependency job, ignoring: Unit systemd-journald-audit.socket has a bad unit file setting.
```

The upstream unit already contains the following, which should make it safe to include regardless:

```ini
[Unit]
ConditionSecurity=audit
ConditionCapability=CAP_AUDIT_READ
```

For reference, this popped up in the context of #[360426](https://redirect.github.com/NixOS/nixpkgs/issues/360426) as well as #[407696](https://redirect.github.com/NixOS/nixpkgs/pull/407696).

Co-authored-by: Bruce Toll <4109762+tollb@users.noreply.github.com>
Signed-off-by: benaryorg <binary@benary.org>
2025-05-18 19:58:59 +00:00
Winter b7ea2eaa7d
nixos/kernel: Module inclusion improvements (#375975) 2025-05-16 01:44:53 -04:00
Will Fancher 028b3e1411 nixos: Use common modulesClosure in scripted and systemd initrd 2025-05-15 00:00:56 -04:00
Gerg-L 98313e2b81
nixos/systemd-initrd: deprecate strip
It only saved ~1MiB of initramfs size, but caused a few issues
like unloadable kernel modules.
2025-05-08 19:08:14 -04:00
nikstur bf2bc08b37
repart: Enable discard option (#397906) 2025-04-28 13:34:32 +02:00
Martin Weinelt fbf76bf72b
make-initrd-ng: Restore stripped file permissions (#398396) 2025-04-13 18:11:19 +02:00
Will Fancher c9ea864d6f nixos/shutdown: Create /run/initramfs with mode 0700 2025-04-13 12:02:16 -04:00
Markus Sütter c6476ca119 repart: Enable discard option
systemd-repart can be configured to not automatically issue BLKDISCARD commands
to the underlying hardware.

This PR exposes this option in the repart module.
2025-04-11 12:46:50 +02:00
Mikael Voss 045fbc389f
nixos/tmpfiles: properly escape argument option
The systemd.tmpfiles.settings.<name>.<path>.<type>.argument option may
contain arbitrary strings. This could allow intentional or unintentional
introduction of new configuration lines.

The argument field cannot be quoted, C‐style \xNN escape sequences are
however permitted. By escaping whitespace and newline characters, the
issue can be mitigated.
2025-04-02 13:23:42 +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](8616af08d9/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
Will Fancher c983091366
nixos/sysusers: respect per user .enable (#388551) 2025-03-20 20:25:49 -04:00
isabel 2c836c5054
nixos/sysusers: respect per user .enable 2025-03-20 20:43:00 +00:00
Will Fancher ecbf53f525
nixos/systemd: conditionally leave out some upstream units (#374214) 2025-03-19 16:58:14 -04:00
Will Fancher b15e9e7d3d
nixos/initrd: add extraFirmwarePaths option (#391166) 2025-03-19 16:51:26 -04:00
Jared Baur dad880d6bf
nixos/systemd: conditionally leave out some upstream units
Some upstream systemd units are conditionally installed into the systemd
output, so we must make sure the feature that enables their installation
is enabled on our side prior to trying to use them.
2025-03-19 08:14:48 -07:00
Benedikt Ritter deb045e057
initrd: implement panic-on-fail interpreterless 2025-03-19 10:23:46 +01:00
Jared Baur ea116654aa
nixos/initrd: add extraFirmwarePaths option
(cherry picked from commit 488d4316b9e1510c9b4a2eeb8d7e2cc66839a1fc)
2025-03-18 20:39:52 -07:00
Florent Charpentier 631bed6ed9 nixos/systemd-repart: add support for repeating settings
fix https://github.com/NixOS/nixpkgs/issues/389478
2025-03-14 19:43:28 +01:00
SebastianStork e0258ad135
nixos/logind: add "sleep" option to logindHandlerType
The "systemctl sleep" command was added in systemd v256.
2025-03-10 19:44:27 +01:00
Peder Bergebakken Sundt 527be14321 nixos/doc: convert links to manpages 2025-02-21 16:31:09 +01:00
nixpkgs-ci[bot] fc7fa5f568
Merge master into staging-next 2025-02-17 00:15:35 +00:00
Arian van Putten 3835432751
systemd-repart: Enable custom --empty flags in initrd (#373414) 2025-02-16 20:03:50 +01:00
K900 daadcbdaac nixos/systemd-stage-1: explicitly add pkgs.runtimeShell dependency
Because it's no longer pkgs.bash (which is interactive), and
can be something else on other platforms anyway.
2025-02-16 19:42:14 +03:00
Maximilian Bosch 4eccb53550
nixos/tmpfiles: fix docs
Closes #381822

Apparently, I swapped `path` and `tmpfiles-type` in
2be50b1efe. Sorry about that 🫠

Also giving
`systemd.tmpfiles.settings.<config-name>.<path>.<tmpfiles-type>.type` a
better default in the manual than `‹name›`, i.e. `‹tmpfiles-type›` so
that it corresponds to the placeholders in the attribute path.
2025-02-14 09:42:43 +01:00
Arian van Putten ff78e34e0b services/journald: introduce audit option
We default this option to null ; which is different
from upstream which defaults this to true.

Defaulting this to true leads to log-spam in /dev/kmesg
and thus in our opinion is a bad default https://github.com/systemd/systemd/issues/15324
2025-02-07 15:58:19 +01:00
Arian van Putten 13b1062730 services/journald: re-enable systemd-journald-audit.socket
This was broken due to https://github.com/systemd/systemd/pull/25687
but we never noticed.
2025-02-07 14:14:53 +01:00
Peder Bergebakken Sundt 75b2b7e946 nixos/*: undo manual linking to known manpage urls
Made with:

jq <doc/manpage-urls.json 'to_entries[] | "rg -F \"[\(.key)](\(.value))\" nixos/ -l | xe sd -F \"[\(.key)](\(.value))\" \"{manpage}`\(.key)`\""' -r  | tr \" \' | bash -x

(requires ripgrep, sd and xe)
2025-01-27 02:47:02 +01:00
Peder Bergebakken Sundt 953f72e76e nixos/*: tag manpage references 2025-01-27 02:47:01 +01:00
WilliButz bc5b78f993
nixos/systemd-tmpfiles: fix ordering of systemd-tmpfiles-setup-sysroot
Prior to this change a service failure would occur when this tmpfiles
service did not finish fast enough and receive a SIGTERM from systemd.
Additionally, `initrd-nixos-activation` is already ordered with
`After=initrd-switch-root.target`.
2025-01-15 15:43:36 +01:00
phaer d2cadf484c repart: Enable custom --empty flags in initrd
By default, systemd-repart refuses to act on empty disk devices, i.e.
those without any existing partition table for safety reasons.

This behaviour can be customized via the `--empty` flag, which we now
expose via the module system. This makes to partition empty disks
on first boot.
2025-01-13 12:13:19 +01:00