diff --git a/pkgs/os-specific/linux/kernel/generic.nix b/pkgs/os-specific/linux/kernel/generic.nix index 5981de6732426..cdad5d1638bfd 100644 --- a/pkgs/os-specific/linux/kernel/generic.nix +++ b/pkgs/os-specific/linux/kernel/generic.nix @@ -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 @@ -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) , kernelArch ? stdenv.hostPlatform.linuxArch , kernelTests ? [] @@ -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 = { diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix index 9c30f1fd70d08..b8bbbdbbd8cad 100644 --- a/pkgs/os-specific/linux/kernel/manual-config.nix +++ b/pkgs/os-specific/linux/kernel/manual-config.nix @@ -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 @@ -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 @@ -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); }) // { 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); @@ -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=-@"] @@ -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 @@ -387,7 +395,7 @@ let # Delete empty directories find -empty -type d -delete - ''; + ''); requiredSystemFeatures = [ "big-parallel" ];