From ff991508ae69d437c933426ad7c9aebffa8ad7ad Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 2 Jan 2024 19:40:57 +0000 Subject: [PATCH] build kernel only once for multiple outputs e.g. vmlinux + zImage --- modules/arch/arm.nix | 1 + modules/kernel.nix | 15 +++++++++++++++ modules/outputs.nix | 12 ++---------- pkgs/kernel/default.nix | 8 +++++--- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/modules/arch/arm.nix b/modules/arch/arm.nix index 1d569bc5..b405bdfc 100644 --- a/modules/arch/arm.nix +++ b/modules/arch/arm.nix @@ -4,6 +4,7 @@ kernel.config = { OF = "y"; }; + kernel.makeTargets = ["arch/arm/boot/zImage"]; hardware.ram.startAddress = lim.parseInt "0x40000000"; system.outputs.u-boot = pkgs.ubootQemuArm; }; diff --git a/modules/kernel.nix b/modules/kernel.nix index 9f134e66..81e72010 100644 --- a/modules/kernel.nix +++ b/modules/kernel.nix @@ -9,6 +9,7 @@ let inherit (pkgs.pseudofile) dir symlink; inherit (pkgs.liminix.networking) address interface; inherit (pkgs.liminix.services) bundle; + inherit (pkgs) liminix; type_service = pkgs.liminix.lib.types.service; @@ -41,11 +42,25 @@ in { }; ''; }; + makeTargets = mkOption { + type = types.listOf types.str; + }; }; }; config = { + system.outputs = + let k = liminix.builders.kernel.override { + inherit (config.kernel) config src extraPatchPhase; + targets = config.kernel.makeTargets; + }; + in { + kernel = k.vmlinux; + zimage = k.zImage; + }; + kernel = rec { modular = true; # disabling this is not yet supported + makeTargets = ["vmlinux"]; config = { IKCONFIG = "y"; IKCONFIG_PROC = "y"; diff --git a/modules/outputs.nix b/modules/outputs.nix index 933a730d..fb7c20b4 100644 --- a/modules/outputs.nix +++ b/modules/outputs.nix @@ -99,26 +99,18 @@ in }; config = { system.outputs = rec { - kernel = liminix.builders.kernel.override { - inherit (config.kernel) config src extraPatchPhase; - }; - zimage = liminix.builders.kernel.override { - targets = ["arch/arm/boot/zImage"]; - inherit (config.kernel) config src extraPatchPhase; - }; dtb = liminix.builders.dtb { inherit (config.boot) commandLine; dts = config.hardware.dts.src; includes = config.hardware.dts.includes ++ [ - "${kernel.headers}/include" + "${o.kernel.headers}/include" ]; }; uimage = liminix.builders.uimage { commandLine = concatStringsSep " " config.boot.commandLine; inherit (config.hardware) loadAddress entryPoint; inherit (config.boot) imageFormat; - inherit kernel; - inherit dtb; + inherit (o) kernel dtb; }; rootdir = let diff --git a/pkgs/kernel/default.nix b/pkgs/kernel/default.nix index b6197fd8..8ff25225 100644 --- a/pkgs/kernel/default.nix +++ b/pkgs/kernel/default.nix @@ -13,6 +13,7 @@ let writeConfig = import ./write-kconfig.nix { inherit lib writeText; }; kconfigFile = writeConfig "kconfig" config; arch = stdenv.hostPlatform.linuxArch; + targetNames = map baseNameOf targets; inherit lib; in stdenv.mkDerivation rec { name = "kernel"; @@ -35,7 +36,7 @@ stdenv.mkDerivation rec { dontStrip = true; dontPatchELF = true; - outputs = ["out" "headers" "modulesupport"]; + outputs = ["out" "headers" "modulesupport"] ++ targetNames; phases = [ "unpackPhase" "butcherPkgconfig" @@ -92,12 +93,13 @@ stdenv.mkDerivation rec { ''; buildPhase = '' - make ${lib.concatStringsSep " " (map baseNameOf targets)} modules_prepare -j$NIX_BUILD_CORES + make ${lib.concatStringsSep " " targetNames} modules_prepare -j$NIX_BUILD_CORES ''; installPhase = '' ${CROSS_COMPILE}strip -d vmlinux - cp ${lib.concatStringsSep " " targets} $out + ${lib.concatStringsSep "\n" (map (f: "cp ${f} \$${baseNameOf f}") targets)} + cp vmlinux $out mkdir -p $headers cp -a include .config $headers/ mkdir -p $modulesupport