Commit graph

389 commits

Author SHA1 Message Date
Grimmauld fad6dbb9e6
nixos/systemd: remove enableCgroupAccounting option 2025-07-28 11:26:44 +02:00
Grimmauld 231c142766
nixos/systemd: remove obsolete DefaultCPUAccounting option
This option is made uncondiotional in systemd 258 [1].
Earlier, it defaulted to true on kernels newer than 4.15,
which applies to all supported nixos kernels.
This means removing the option does not change behavior.

[1] 29da53dde3
2025-07-28 11:26:37 +02:00
Grimmauld f47b100763
nixos/systemd: remove obsolete DefaultBlockIOAccounting option
This option is now being ignored by systemd,
so we do not need to explicitly define it.
2025-07-28 11:26:34 +02:00
Grimmauld 265152f770
nixos/systemd: explicitly set systemd.settings.Manager.Default*Accounting 2025-07-28 11:26:30 +02:00
Grimmauld 9c429f004d
nixos/systemd: remove obsolete definition for DefaultLimitCORE
The limit was introduced in 2016 in 840f3230a2,
and broken iin 2019 in bafc256915. Since then,
it is the exact same as systemd itself sets as default.
2025-07-28 11:26:27 +02:00
Grimmauld 69e833f187
nixos/systemd: set DefaultLimitCORE in systemd.settings.Manager explicitly 2025-07-28 11:26:24 +02:00
Grimmauld 62acc59148
nixos/systemd: move systemd.watchdog.* to systemd.settings.Manager 2025-07-28 11:26:21 +02:00
Grimmauld 493f1339b0
nixos/systemd: move systemd.watchdog.* to systemd.settings.Manager 2025-07-28 11:26:08 +02:00
Grimmauld 4d3ab0e8d3
nixos/systemd: make systemd.managerEnvironment affect systemd.settings.Manager 2025-07-28 11:24:39 +02:00
Grimmauld 897933fc9e
nixos/systemd: move systemd.managerEnvironment to systemd.settings.Manager.ManagerEnvironment 2025-07-28 11:24:36 +02:00
Grimmauld 1a846a2fff
nixos/systemd: remove systemd.extraConfig 2025-07-28 11:24:26 +02:00
Grimmauld ebaf7a33ec
nixos/systemd: add settings.Manager option 2025-07-28 11:23:57 +02:00
Grimmauld fb51cc802d
nixos/systemd: run0: enable setLoginUid, disable pamMount
This brings our `run0` in line with the upstream defaults:
bcc73cafdb/src/run/systemd-run0.in

While working on `auditd`, i noticed differences in how `run0` behaves
in regard to `/proc/$pid/sessionid` and `/proc/$pid/loginuid`. Particularly,
both files were set to `4294967295`, the magic value denoting `unset`.

While the manual page says elevators such as sudo should not set the loginuid,
run0 is a bit of a special case: The unit spawned by it is not child of
the running user session, and as such there is no id to inherit.

`systemd` upstream uses `pam_loginuid`, and for consistency we should too.
Especially because it prevents a whole lot of pain when working with `auditd`.

As to pam mounts:
On nixos we enable those if they are globally enabled. Upstream does not.
Considering the password entered into polkit is usually not the user password
of the account which will own the unit, pam mount will fail for any partition
which requires a password. Thus it makes sense to also disable pam mounts
for our run0, it prevents unnecessary unexpected pain.
2025-07-25 23:49:59 +02:00
Wolfgang Walther 5a0711127c
treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
Jason Yundt d54262911c nixos/systemd: fix run0 failing to run commands
Fixes #361592.

I was able to test this change by doing the following:

1. Create a file named “test-systemd-run0.nix” that contains this Nix
expression:

    let
      nixpkgs = /path/to/nixpkgs;
      pkgs = import nixpkgs { };
    in
    pkgs.testers.runNixOSTest {
      name = "test-systemd-run0";
      nodes.machine = {
        security.polkit.enable = true;
      };
      testScript = ''
        start_all()
        machine.succeed("run0 env")
      '';
    }

2. Replace “/path/to/nixpkgs” with the actual path to an actual copy of
Nixpkgs.

3. Run the integration test by running this command:

    nix-build <path to test-systemd-run0.nix>
2025-06-24 10:18:56 -04:00
Paul Haerle 86a1af8a7b
nixos/systemd: clarify what enableStrictShellChecks checks (#401460) 2025-04-27 14:15:15 +02:00
Scott Edlund 02555cd0bd nixos/systemd: clarify what enableStrictShellChecks checks
the specifics of this option are in the release notes, but bring
them into the documentation.
2025-04-26 01:46:12 +08:00
Silvan Mosberger e52d633a63 Merge remote-tracking branch 'upstream/staging-next' into staging 2025-04-02 18:30:54 +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
nixpkgs-ci[bot] 47fbdfd4fc
Merge staging-next into staging 2025-03-20 00:16:05 +00: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
Philip Taron f4dd3ba6e0
systemd: make systemd-ssh-generator work (#372979) 2025-03-15 21:59:59 -07:00
Marie Ramlow aab69d7f19 nixos/systemd: include sshd in PATH if openssh is enabled
This enables systemd-ssh-generator to find the sshd binary.
2025-03-14 18:34:50 +01:00
John Titor f597c68e7b
nixos/boot/systemd: enable tracefs
tracefs is a special-purpose filesystem in Linux used for tracing filesystem and kernel operations.

This was added to the kernel back in 2015 to replace debugfs. For security reasons, some system do not mount debugfs at all. Tracefs reduces the attack surface by allowing to trace without mounting debugfs. Additionally it provides features not supported by debugfs (such as calls for mkdir and rmdir

Debian and Arch Linux both enable this by default.
RHEL 8 and later, they enable tracefs by default.

Signed-off-by: John Titor <50095635+JohnRTitor@users.noreply.github.com>
2025-03-10 22:27:41 +05:30
Michele Guerini Rocco d05074f981
nixos/getty: only include if config.console.enable == true (#363533) 2025-02-18 11:44:42 +01:00
therainisme 0a12b8d03d
systemd: fix typo in boot.kernelParams (hierachy → hierarchy) 2025-02-07 12:06:23 +08:00
rnhmjoj 2370696dff
nixos/systemd: don't require network-online.target for multi-user.target v2
This is another attempt at 62f30634 after the original change was reverted in
0d85bf0e because NetworkManager and other tests were broken.
2024-12-16 18:12:47 +01:00
Moritz Sanft 7fb2f407c0
nixos/getty: only include if config.console.enable
This makes it so that the getty units are only included if
`config.console.enable` is set to `true`. Previously, they would be
included, but disabled in that case, which is unnecessary.
2024-12-16 08:45:10 +01:00
Aleksana 81dacf0c91
nixos/systemd: fix enableStrictShellChecks description (#348513) 2024-11-05 23:03:19 +08:00
Frédéric Christ 8f4b41cfd4 nixos/systemd: Enable systemd-machine-id-commit.service
Prior to this contribution, every boot with a default configuration was
considered `ConditionFirstBoot=true` by systemd, since /etc/machine-id
was not commited to disk.

This also extends the systemd with a check for subsequent boots not
being considered first boots.
2024-10-25 14:03:15 +02:00
Sandro eafd968bfd
nixos/systemd: fix enableStrictShellChecks description 2024-10-14 13:17:29 +02:00
r-vdp 2b224f0e3c
nixos/systemd: allow using writeShellApplication for systemd unit scripts 2024-10-08 12:01:48 +02:00
Florian Klink b66c0f2e99
nixos/systemd: let systemd setup /etc/machine-id (#327552) 2024-10-01 15:05:59 +03:00
Will Fancher 1f34534920
Systemd tpm fixes (#343307) 2024-09-25 17:17:57 -04:00
Artturin e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
2024-09-25 00:04:37 +03:00
Will Fancher 5034450095 nixos/systemd: Factor out tpm2 support into separate module 2024-09-20 14:33:35 -04: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 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
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
Arian van Putten 45e041902f nixos/systemd: drop support for legacy cgroup hierachy 2024-07-31 13:49:58 +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
nikstur d4a80b6d0c systemd: 255.6 -> 256.2 2024-07-21 06:31:37 -04:00
Jared Baur 115c1d6901
nixos/systemd: add presets to ignore all other presets
One of the main premises of NixOS is being able to declaratively specify
the services enabled/running on a machine. Since systemd presets allow
to bypass this this declarative nature, add a single preset with the
highest priority (prefixed with "00") that makes systemd ignore all
other presets.
2024-07-16 16:52:17 -07:00
Jared Baur 2b982b99ac
nixos/systemd: let systemd setup /etc/machine-id
If we let systemd setup /etc/machine-id, we get to use
ConditionFirstBoot in systemd units and any other integrations related
to systemd's detection of first boot. See machine-id(5).
2024-07-15 21:52:28 -07:00
Michael Franzl cae086d605
nixos/virtualisation: increase priority for libvirt NSS modules
When `services.resolved` is enabled, then `resolve [!UNAVAIL=return]`
is added to `system.nssDatabases.hosts` with priority 501,
which prevents lower-priority NSS modules from running
unless systemd-resolved is not available.

Quoting from `man nss-resolve`:

> To activate the NSS module, add "resolve [!UNAVAIL=return]" to the line
> starting with "hosts:" in /etc/nsswitch.conf. Specifically, it is
> recommended to place "resolve" early in /etc/nsswitch.conf's "hosts:"
> line. It should be before the "files" entry, since systemd-resolved
> supports /etc/hosts internally, but with caching. To the contrary, it
> should be after "mymachines", to give hostnames given to local VMs and
> containers precedence over names received over DNS. Finally, we
> recommend placing "dns" somewhere after "resolve", to fall back to
> nss-dns if systemd-resolved.service is not available.

Note that the man page (just) recommends "early" and means with this
"before the 'files' and 'dns' entries". It does not insist on being
first or excluding other modules.

For this reason, libvirt NSS modules should run before the `resolve`
module. They should come right next to `mymachines` because both are
conceptually very similar -- they resolve local VMs/containers.

Since the data source of the libvirt NSS modules are local
plain text files (see source code of the libvirt NSS module),
no performance impact is expected form this raise of priorities.

Other NSS modules in NixOS also explicitly set their priority, which is
why this change increases consistency.

Fixes #322022
2024-06-25 20:22:14 +02:00
Dawid Dziurla fbbc41f7da
nixos/systemd: simplify hooks function 2024-06-03 11:15:59 +02:00
Dawid Dziurla 25ad0cdbfc
nixos/systemd: link user-generators 2024-05-30 19:52:22 +02:00
r-vdp 9258f57625
systemd: add a name option to all systemd units
This allows us to set things like dependencies in a way that we can
catch typos at eval time.
So instead of
```nix
systemd.services.foo.wants = [ "bar.service" ];
```
we can write
```nix
systemd.services.foo.wants = [ config.systemd.services.bar.name ];
```
which will throw an error if no such service has been defined.

Not all cases can be done like this (eg template services), but in a lot
of cases this will allow to avoid typos.

There is a matching option on the unit option
(`systemd.units."foo.service".name`) as well.
2024-04-15 11:32:45 +02:00
Will Fancher df32b558b5 nixos/systemd: Enable debug-shell.service. 2024-03-29 17:32:38 -04:00