Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion pkgs/os-specific/linux/kernel/generic.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
let
# Map of images representations to legacy Makefile targets.
defaultMapKernelToInstallTargets = {
"uImage" = "uinstall";
"zImage" = "zinstall";
"Image.gz" = "zinstall";
"vmlinuz.efi" = "zinstall";
};
in
{ buildPackages
, callPackage
, perl
Expand Down Expand Up @@ -70,6 +79,12 @@ lib.makeOverridable ({ # The kernel source tarball.
# easy overrides to stdenv.hostPlatform.linux-kernel members
, autoModules ? stdenv.hostPlatform.linux-kernel.autoModules
, preferBuiltin ? stdenv.hostPlatform.linux-kernel.preferBuiltin or false
, kernelTargets ?
if stdenv.hostPlatform.isAarch64 then
["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)

, kernelArch ? stdenv.hostPlatform.linuxArch
, kernelTests ? []

Expand Down Expand Up @@ -214,7 +229,7 @@ let
}; # end of configfile derivation

kernel = (callPackage ./manual-config.nix { inherit lib stdenv buildPackages; }) (basicArgs // {
inherit kernelPatches randstructSeed extraMakeFlags extraMeta configfile modDirVersion;
inherit kernelPatches randstructSeed extraMakeFlags extraMeta configfile modDirVersion kernelTargets installTargets;
pos = builtins.unsafeGetAttrPos "version" args;

config = {
Expand Down
34 changes: 21 additions & 13 deletions pkgs/os-specific/linux/kernel/manual-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ in lib.makeOverridable ({
src,
# a list of { name=..., patch=..., extraConfig=...} patches
kernelPatches ? [],
# kernel image build targets like Image, bzImage, Image.gz, vmlinuz.efi
kernelTargets ? [],
# a list of install targets, e.g. :
# - uinstall for uImage, U-Boot wrapped image
# - zinstall for zImage, self-extracting images
# - install, the generic binary image
installTargets ? [],
# The kernel .config file
configfile,
# Manually specified nixexpr representing the config
Expand Down Expand Up @@ -64,7 +71,9 @@ let
# Shadow the un-defaulted parameter; don't want null.
modDirVersion = modDirVersion_;
inherit (lib)
hasAttr getAttr optional optionals optionalString optionalAttrs maintainers platforms;
hasAttr getAttr optional optionals optionalString optionalAttrs genAttrs replaceStrings maintainers platforms;

targetsToOutput = genAttrs kernelTargets (target: replaceStrings ["."] ["-"] target);

drvAttrs = config_: kernelConf: kernelPatches: configfile:
let
Expand Down Expand Up @@ -128,10 +137,10 @@ let
++ optionals withRust [ rustc rust-bindgen ]
;

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.

passthru = rec {
inherit version modDirVersion config kernelPatches configfile
moduleBuildDependencies stdenv;
moduleBuildDependencies stdenv targetsToOutput;
inherit isZen isHardened isLibre withRust;
isXen = lib.warn "The isXen attribute is deprecated. All Nixpkgs kernels that support it now have Xen enabled." true;
baseVersion = lib.head (lib.splitString "-rc" version);
Expand Down Expand Up @@ -242,7 +251,7 @@ let

buildFlags = [
"KBUILD_BUILD_VERSION=1-NixOS"
kernelConf.target
] ++ kernelTargets ++ [
"vmlinux" # for "perf" and things like that
] ++ optional isModular "modules"
++ optionals buildDTBs ["dtbs" "DTC_FLAGS=-@"]
Expand Down Expand Up @@ -309,15 +318,14 @@ let
export HOME=${installkernel}
'';

# Some image types need special install targets (e.g. uImage is installed with make uinstall on arm)
installTargets = [
(kernelConf.installTarget or (
/**/ if kernelConf.target == "uImage" && stdenv.hostPlatform.linuxArch == "arm" then "uinstall"
else if kernelConf.target == "zImage" || kernelConf.target == "Image.gz" || kernelConf.target == "vmlinuz.efi" then "zinstall"
else "install"))
];
# Some image types need special install targets (e.g. uImage is installed with make uinstall)
installTargets = if installTargets == [ ] then [ "install" ] else installTargets;

postInstall = optionalString isModular ''
postInstall = (lib.concatStringsSep "\n" (lib.mapAttrsToList (target: output: ''
mkdir -p "''${${output}}"
moveToOutput "${target}" "''${${output}}"
ln -sf "''${${output}}/${target}" "$out/${target}"
'') targetsToOutput)) + (optionalString isModular ''
mkdir -p $dev
cp vmlinux $dev/
if [ -z "''${dontStrip-}" ]; then
Expand Down Expand Up @@ -387,7 +395,7 @@ let

# Delete empty directories
find -empty -type d -delete
'';
'');

requiredSystemFeatures = [ "big-parallel" ];

Expand Down