From 47c370f495a4b092fdca05f25683d2f7024e89fb Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 22 Nov 2026 11:47:48 +0000 Subject: base/systemd.nix: a slimmer systemd, optional nixpkgs' systemd comes with much a guest has no use for: importd (with gnupg and openldap), cryptsetup, TPM2, FIDO2, homed, repart, sysupdate, portabled, machined, nspawn and vmspawn, journal-remote (microhttpd, gnutls), coredump (elfutils), BPF (libbpf), qrencode, pwquality, AppArmor. And dbus brings in a second systemd, systemd-minimal (23M), X11's libraries, and AppArmor, too. Leaving all that out means building systemd, dbus and dbus-broker (which links libsystemd) from source, on every nixpkgs bump, so it's a base module (--arg base '[ base/systemd.nix ]'), for whoever thinks that's worth it. NixOS leaves out the units of what the package lacks; coredump the base system turns off already, and the module takes systemd-bsod out of the initrd (where NixOS has it unconditionally), as systemd builds it only with qrencode. --- base/systemd.nix | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 base/systemd.nix (limited to 'base') diff --git a/base/systemd.nix b/base/systemd.nix new file mode 100644 index 0000000..1bb0d0f --- /dev/null +++ b/base/systemd.nix @@ -0,0 +1,50 @@ +# A slimmer systemd, without what a guest has no use for, as a module for +# the base system: +# nix-build pkgs/run-firecracker-vm --arg base '[ base/systemd.nix ]' +# Built from source (no binary cache has it), on every nixpkgs bump, as are +# dbus, against it instead of systemd-minimal (which comes in only with +# dbus), and without X11 and AppArmor, and dbus-broker, which links +# libsystemd. The initrd gets it, too. NixOS leaves out the units of +# what the package doesn't have; coredump, which it doesn't, the base +# system turns off already. +{ config, lib, pkgs, ... }: +{ + systemd.package = pkgs.systemd.override { + withApparmor = false; + withCoredump = false; # elfutils + withCryptsetup = false; + withFido2 = false; + withHomed = false; + withImportd = false; # gnupg, openldap + withLibBPF = false; + withMachined = false; + withNspawn = false; + withPasswordQuality = false; + withPortabled = false; + withQrencode = false; # so no systemd-bsod, see below + withRemote = false; # microhttpd, gnutls + withRepart = false; + withSysupdate = false; + withTpm2Tss = false; + withVmspawn = false; + }; + # NixOS's initrd has systemd-bsod (emergency messages full-screen, with a + # QR code), which systemd builds only with qrencode. + boot.initrd.systemd.suppressedUnits = [ "systemd-bsod.service" ]; + boot.initrd.systemd.suppressedStorePaths = [ + "${config.boot.initrd.systemd.package}/lib/systemd/systemd-bsod" + ]; + # dbus against it, without X11 and AppArmor (which has no switch there). + services.dbus.dbusPackage = (pkgs.dbus.override { + systemdMinimal = config.systemd.package; + x11Support = false; + }).overrideAttrs (old: { + buildInputs = lib.remove pkgs.libapparmor old.buildInputs; + mesonFlags = map (f: if f == "-Dapparmor=enabled" then "-Dapparmor=disabled" else f) old.mesonFlags; + }); + # It links libsystemd: with nixpkgs' systemd, the guest would have both. + services.dbus.brokerPackage = pkgs.dbus-broker.override { + systemd = config.systemd.package; + dbus = config.services.dbus.dbusPackage; + }; +} -- cgit v1.3.1