diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index 022e459c3945a..e81e35d0ae7af 100644 --- a/lib/systems/inspect.nix +++ b/lib/systems/inspect.nix @@ -48,6 +48,7 @@ rec { isRiscV64 = { cpu = { family = "riscv"; bits = 64; }; }; isRx = { cpu = { family = "rx"; }; }; isSparc = { cpu = { family = "sparc"; }; }; + isSparc64 = { cpu = { family = "sparc"; bits = 64; }; }; isWasm = { cpu = { family = "wasm"; }; }; isMsp430 = { cpu = { family = "msp430"; }; }; isVc4 = { cpu = { family = "vc4"; }; }; diff --git a/lib/systems/platforms.nix b/lib/systems/platforms.nix index 0b6a9f3891da7..4080e703fba68 100644 --- a/lib/systems/platforms.nix +++ b/lib/systems/platforms.nix @@ -14,7 +14,6 @@ rec { baseConfig = "defconfig"; # Build whatever possible as a module, if not stated in the extra config. autoModules = true; - target = "bzImage"; }; }; @@ -27,7 +26,6 @@ rec { name = "PowerNV"; baseConfig = "powernv_defconfig"; - target = "vmlinux"; autoModules = true; # avoid driver/FS trouble arising from unusual page size extraConfig = '' @@ -384,7 +382,6 @@ rec { # which our initrd builder can't currently do easily. USB_XHCI_TEGRA m ''; - target = "Image"; }; gcc = { arch = "armv8-a"; @@ -534,7 +531,6 @@ rec { riscv-multiplatform = { linux-kernel = { name = "riscv-multiplatform"; - target = "Image"; autoModules = true; baseConfig = "defconfig"; DTB = true; diff --git a/pkgs/os-specific/linux/kernel/common-config.nix b/pkgs/os-specific/linux/kernel/common-config.nix index 688c13499b1ab..16c5fad1a308b 100644 --- a/pkgs/os-specific/linux/kernel/common-config.nix +++ b/pkgs/os-specific/linux/kernel/common-config.nix @@ -894,7 +894,8 @@ let EFI_STUB = yes; # EFI bootloader in the bzImage itself EFI_GENERIC_STUB_INITRD_CMDLINE_LOADER = - whenOlder "6.2" (whenAtLeast "5.8" yes); # initrd kernel parameter for EFI + whenOlder "6.2" (whenAtLeast "5.8" yes); # initrd kernel parameter for EFI + EFI_ZBOOT = whenAtLeast "6.1" yes; # Generic compression support for EFI payloads CGROUPS = yes; # used by systemd FHANDLE = yes; # used by systemd SECCOMP = yes; # used by systemd >= 231 diff --git a/pkgs/os-specific/linux/kernel/generic.nix b/pkgs/os-specific/linux/kernel/generic.nix index 6605213490539..b3be147996ae9 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. + defaultMapImageToTargets = { + "uImage" = "uinstall"; + "zImage" = "zinstall"; + "Image.gz" = "zinstall"; + "vmlinux" = "install"; + }; +in { buildPackages , callPackage , perl @@ -57,6 +66,11 @@ # easy overrides to stdenv.hostPlatform.linux-kernel members , autoModules ? stdenv.hostPlatform.linux-kernel.autoModules or true , preferBuiltin ? stdenv.hostPlatform.linux-kernel.preferBuiltin or false +, kernelTarget ? null +# FIXME: this should go whenever we can rely on KBUILD_IMAGE to install +# our kernel targets, MIPS is probably the only recent kernel in-tree +# which does not support that yet. +, installTargets ? [ ] , kernelArch ? stdenv.hostPlatform.linuxArch , kernelTests ? [] , nixosTests @@ -92,6 +106,41 @@ let ia32Emulation = true; } // features) kernelPatches; + + # Legacy compatibility layer for + # systems relying on `installTarget` + # being a property of the platform. + defaultKernelInstallTargets = [ + stdenv.hostPlatform.linux-kernel.installTarget or + (defaultMapImageToTargets.${stdenv.hostPlatform.linux-kernel.target or "vmlinux"}) + ]; + + # Default kernel target in the case no install target or kernelTarget is mentioned + # We aim to derive the "best" kernel given the current constraints. + defaultKernelTarget = + if stdenv.hostPlatform.isx86 + then "bzImage" + else if stdenv.hostPlatform.isAarch64 + then "Image.gz" + else if (stdenv.hostPlatform.isAarch || stdenv.hostPlatform.isArmv7) + then "vmlinuz" + else if stdenv.hostPlatform.isMips + then "vmlinux" + else if stdenv.hostPlatform.isRiscV + then "Image.xz" + else if stdenv.hostPlatform.isSparc64 + then "Image.gz" + else if stdenv.hostPlatform.isSparc + then "vmlinux" + else if stdenv.hostPlatform.isS390 + then "bzImage" + else if stdenv.hostplatform.isLoongArch64 + then "Image.gz" + else "vmlinux"; + + finalKernelTarget = if kernelTarget == null then defaultKernelTarget else kernelTarget; + finalInstallTargets = if installTargets != [] then defaultKernelInstallTargets else installTargets; + commonStructuredConfig = import ./common-config.nix { inherit lib stdenv version; @@ -193,6 +242,9 @@ let kernel = (callPackage ./manual-config.nix { inherit lib stdenv buildPackages; }) (basicArgs // { inherit kernelPatches randstructSeed extraMakeFlags extraMeta configfile; + kernelTarget = finalKernelTarget; + # kernelTarget has precedence + installTargets = if installTargets != [ ] then finalInstallTargets else [ ]; pos = builtins.unsafeGetAttrPos "version" args; config = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; }; @@ -201,6 +253,10 @@ let passthru = basicArgs // { features = kernelFeatures; inherit commonStructuredConfig structuredExtraConfig extraMakeFlags isZen isHardened isLibre; + + kernelTarget = if kernelTarget == null then defaultKernelTarget else kernelTarget; + installTargets = if installTargets != [] then defaultKernelInstallTargets else installTargets; + isXen = lib.warn "The isXen attribute is deprecated. All Nixpkgs kernels that support it now have Xen enabled." true; # Adds dependencies needed to edit the config: diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix index 677cc9363da43..7dcb503fae181 100644 --- a/pkgs/os-specific/linux/kernel/manual-config.nix +++ b/pkgs/os-specific/linux/kernel/manual-config.nix @@ -30,6 +30,16 @@ in lib.makeOverridable ({ src, # a list of { name=..., patch=..., extraConfig=...} patches kernelPatches ? [], + # KBUILD_IMAGE + kernelTarget ? null, + # 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 + # those targets are legacy and are present + # only for compatibility with old kernels or MIPS for now. + # prefer KBUILD_IMAGE instead. + installTargets ? [], # The kernel .config file configfile, # Manually specified nixexpr representing the config @@ -88,14 +98,16 @@ let isModular = config.isYes "MODULES"; kernelConf = stdenv.hostPlatform.linux-kernel; - target = kernelConf.target or "vmlinux"; - buildDTBs = kernelConf.DTB or false; in assert lib.versionOlder version "5.8" -> libelf != null; assert lib.versionAtLeast version "5.8" -> elfutils != null; +# An kernel image target must be explicit as we cannot learn it +# from the defaults in the different Makefile. +assert kernelTarget != null || installTargets != []; + stdenv.mkDerivation ({ pname = "linux"; inherit version src; @@ -220,6 +232,7 @@ stdenv.mkDerivation ({ ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "CROSS_COMPILE=${stdenv.cc.targetPrefix}" ] ++ (kernelConf.makeFlags or []) + ++ lib.optional (kernelTarget != null) "KBUILD_IMAGE=${kernelTarget}" ++ extraMakeFlags; karch = stdenv.hostPlatform.linuxArch; @@ -296,12 +309,7 @@ stdenv.mkDerivation ({ ''; # Some image types need special install targets (e.g. uImage is installed with make uinstall) - installTargets = [ - (kernelConf.installTarget or ( - /**/ if target == "uImage" then "uinstall" - else if target == "zImage" || target == "Image.gz" then "zinstall" - else "install")) - ]; + installTargets = if installTargets == [ ] then [ "install" ] else installTargets; postInstall = optionalString isModular '' if [ -z "''${dontStrip-}" ]; then @@ -332,7 +340,8 @@ stdenv.mkDerivation ({ cp -HR $buildRoot/$f $dev/lib/modules/${modDirVersion}/build/$f fi done - ln -s $dev/lib/modules/${modDirVersion}/build/vmlinux $dev + mkdir $debug/ + ln -s $dev/lib/modules/${modDirVersion}/build/vmlinux $debug # !!! No documentation on how much of the source tree must be kept # If/when kernel builds fail due to missing files, you can add @@ -424,5 +433,5 @@ stdenv.mkDerivation ({ } // optionalAttrs (pos != null) { inherit pos; } // optionalAttrs isModular { - outputs = [ "out" "dev" ]; + outputs = [ "out" "dev" "debug" ]; }))