liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit ff991508ae69d437c933426ad7c9aebffa8ad7ad
parent e4ed9dbec92efa7cf6612c5e27b4893d0ee6b14d
Author: Daniel Barlow <dan@telent.net>
Date:   Tue,  2 Jan 2024 19:40:57 +0000

build kernel only once for multiple outputs

e.g. vmlinux + zImage

Diffstat:
Mmodules/arch/arm.nix | 1+
Mmodules/kernel.nix | 15+++++++++++++++
Mmodules/outputs.nix | 12++----------
Mpkgs/kernel/default.nix | 8+++++---
4 files changed, 23 insertions(+), 13 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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