Skip to content

linux: multiple outputs for kernel targets#324419

Draft
fpletz wants to merge 1 commit intoNixOS:stagingfrom
fpletz:linux-targets-outputs
Draft

linux: multiple outputs for kernel targets#324419
fpletz wants to merge 1 commit intoNixOS:stagingfrom
fpletz:linux-targets-outputs

Conversation

@fpletz
Copy link
Member

@fpletz fpletz commented Jul 3, 2024

Description of changes

Preview of an alternative idea for #244706 and inspired by #287122. Needs #239721.

This adds outputs for all built kernel targets and provides symlinks to all built images in the default output for compatibility. This way we can get rid of lib.platforms.*.linux-kernel.target eventually and we don't have to build the kernel multiple times for every target.

Looking for feedback. Is this maybe a way to go?

TODO

  • Change NixOS bootloader code to use the outputs
  • Don't depend on all images in the NixOS system closure
  • Remove target from lib.platforms.*.linux-kernel
  • Maybe split modules and dtbs in separate outputs
  • Code cleanups for better readability

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/)
  • 24.11 Release Notes (or backporting 23.11 and 24.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.

This adds outputs for all built kernel targets and provides symlinks to
all built images in the default output for compatibility. This way we
can get rid of `lib.platforms.*.linux-kernel.target` eventually and we
don't have to build the kernel multiple times for every target.
@github-actions github-actions bot added the 6.topic: kernel The Linux kernel label Jul 3, 2024
@ofborg ofborg bot added 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. labels Jul 4, 2024
;

in (optionalAttrs isModular { outputs = [ "out" "dev" ]; }) // {
in (optionalAttrs isModular { outputs = [ "out" "dev" ] ++ (lib.attrValues targetsToOutput); }) // {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would end up wanting to have outputs even if the kernel wasn't built with module support.

@jmbaur
Copy link
Contributor

jmbaur commented Jul 10, 2024

Overall really like the concept! Would be very nice to be able to easily switch between different kernel image types without incurring the cost of a rebuild. I think using derivation outputs as the differentiator between different image types seems like the right way to go here. I think we will also need to modify https://github.com/nixos/nixpkgs/blob/d5e0de612a503ff9c1a3fe2d0853c0fbbe336fbd/nixos/modules/system/activation/top-level.nix#L104 to take account for this as well. This also probably makes that option (system.boot.loader.kernelFile) the best way to go for choosing the kernel image type for a given nixos config, so it probably makes sense to make that option no longer marked as internal.

["Image" "vmlinuz.efi"]
else
[stdenv.hostPlatform.linux-kernel.target]
, installTargets ? lib.unique (map (target: defaultMapKernelToInstallTargets.${target} or "install") kernelTargets)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how valuable it is to have a separate argument for installTargets, as I can't imagine a scenario where the kernelTargets passed wouldn't be directly correlated to installTargets. My understanding is the linux makefiles accept the kernel image targets as make targets already (e.g. make bzImage works directly, so something like make Image vmlinuz.efi should work as well)

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Feb 15, 2025
@nixpkgs-ci nixpkgs-ci bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: kernel The Linux kernel 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.

3 participants