Skip to content

{nixos/}systemd: enable BTF; enable {nsresourced,mountfsd} - #404715

Closed
msanft wants to merge 4 commits into
NixOS:masterfrom
msanft:msanft/systemd-btf
Closed

msanft wants to merge 4 commits into
NixOS:masterfrom
msanft:msanft/systemd-btf

Conversation

@msanft

@msanft msanft commented May 6, 2025

Copy link
Copy Markdown
Contributor

This adds support for rootless systemd-nspawn containers on NixOS by doing a few things:

  • Changing the linuxManualConfig builder by unconditionally emitting a vmlinux output, not just when CONFIG_MODULES=y (also removing an IFD requirement for that).
  • Adding BTF information for the systemd package's BPF programs, which are a prerequisite for nsresourced and mountfsd. This is achieved by building a minimal custom kernel, generating a vmlinux.h file from that, and consuming that in systemd. This does not create a strong dependency between the systemd package and a specific kernel version, as
    the header file is only used for initial compilation, and BPF symbols are being relocated at runtime later on using BPF CO-RE.
  • Adding toggles for the systemd-{nsresourced,mountfsd} binaries in the systemd package. These are passed-through, to be consumed by the NixOS module.
  • Conditionally enabling the aforementioned units in the NixOS module for systemd.

Change can be quickly verified by the following pre-change and post-change:

sudo $(nix build .#systemd.out --print-out-paths --no-link)/lib/systemd/systemd-nsresourced

Prior to the change, this will show:

Not setting up BPF subsystem, as functionality has been disabled at compile time.

After the change:

userns-restrict BPF-LSM program userns_restrict_path_chown attached.
userns-restrict BPF-LSM program userns_restrict_path_mkdir attached.
userns-restrict BPF-LSM program userns_restrict_path_mknod attached.
userns-restrict BPF-LSM program userns_restrict_path_symlink attached.
userns-restrict BPF-LSM program userns_restrict_path_link attached.
userns-restrict BPF-LSM program userns_restrict_free_user_ns attached.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

msanft added 4 commits May 6, 2025 20:13
This adds a `vmlinux` output to the `linuxManualConfig` derivation, making it easier to access the kernel ELF file without creating a modular kernel, which previously has been the requirement for the `dev` output, in which the `vmlinux` file lived.
This adds the necessary BTF information for systemd's BPF programs. This relies on a purpose-built, minimal kernel, from which the `vmlinux.h` header file with the kernel-internal definitions is generated. Note that the systemd derivation is not depending on that specific kernel, it's just used for initial compilation. At runtime, the symbols are relocated using BPF CO-RE.
This adds enable knobs for nsresourced and mountfsd. These toggles are passed-through, so that they can be consumed by the NixOS module.
This conditionally enables the nsresourced and mountfsd services, which are used to enable rootless systemd-nspawn containers.
@msanft
msanft requested review from ElvishJerricco, K900 and alyssais May 6, 2025 18:56
@github-actions github-actions Bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: kernel The Linux kernel 8.has: module (update) This PR changes an existing module in `nixos/` 6.topic: systemd Software suite that provides an array of system components for Linux operating systems. labels May 6, 2025
@nix-owners
nix-owners Bot requested review from aanderse, arianvp and flokli May 6, 2025 18:58
@github-actions github-actions Bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. labels May 6, 2025
@msanft

msanft commented May 6, 2025

Copy link
Copy Markdown
Contributor Author

Didn't anticipate that many rebuilds, will retarget against staging later.

@msanft

msanft commented May 7, 2025

Copy link
Copy Markdown
Contributor Author

Closing this while I'm retargeting to staging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: kernel The Linux kernel 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: systemd Software suite that provides an array of system components for Linux operating systems. 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants