diff --git a/test/Makefile b/test/Makefile index 0c17cd660..10a04bffa 100644 --- a/test/Makefile +++ b/test/Makefile @@ -157,6 +157,17 @@ nix_gc: @nix-collect-garbage -d @nix-store --optimise +# This target is used to accelerate CI workflows, e.g., `benchmark_x86` and `benchmark_x86_tdx`. +initramfs_pkgs: + @nix-build \ + nix/default.nix \ + --tarball-ttl $(NIXPKGS_CACHE_TTL) \ + $(NIX_QUIET) \ + --argstr target x86_64 \ + --arg enableBenchmark true \ + --out-link /nix/var/nix/gcroots/auto/x86_64-initramfs-with-benchmark \ + -A initramfs-image + $(EXT2_IMAGE): @mkdir -p $(BUILD_DIR) @dd if=/dev/zero of=$(EXT2_IMAGE) bs=2G count=1 diff --git a/test/nix/benchmark/default.nix b/test/nix/benchmark/default.nix index 1baea7e47..a02905aa6 100644 --- a/test/nix/benchmark/default.nix +++ b/test/nix/benchmark/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, callPackage, hostPlatform, pkgsHostTarget, }: rec { +{ lib, stdenvNoCC, callPackage, hostPlatform, pkgsHostTarget, }: rec { # Use `--esx` flag to enable `CONFIG_NO_SHM` and disable `CONFIG_HAVE_TIMERFD_CREATE`. fio = pkgsHostTarget.fio.overrideAttrs (_: { configureFlags = [ "--esx" ]; }); hackbench = callPackage ./hackbench.nix { }; @@ -14,7 +14,7 @@ sqlite-speedtest1 = callPackage ./sqlite-speedtest1.nix { }; sysbench = if hostPlatform.isx86_64 then pkgsHostTarget.sysbench else null; - package = stdenv.mkDerivation { + package = stdenvNoCC.mkDerivation { pname = "benchmark"; version = "0.1.0"; src = lib.fileset.toSource { diff --git a/test/nix/initramfs-image.nix b/test/nix/initramfs-image.nix index ecb7d161e..d00a19ff1 100644 --- a/test/nix/initramfs-image.nix +++ b/test/nix/initramfs-image.nix @@ -1,5 +1,5 @@ -{ stdenv, pkgsBuildBuild, initramfs, compressed, }: -stdenv.mkDerivation { +{ stdenvNoCC, pkgsBuildBuild, initramfs, compressed, }: +stdenvNoCC.mkDerivation { name = "initramfs-image"; nativeBuildInputs = with pkgsBuildBuild; [ cpio gzip ]; buildCommand = '' diff --git a/test/nix/initramfs.nix b/test/nix/initramfs.nix index 4cfc045a4..ca2492632 100644 --- a/test/nix/initramfs.nix +++ b/test/nix/initramfs.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchFromGitHub, hostPlatform, writeClosure, busybox, apps +{ lib, stdenvNoCC, fetchFromGitHub, hostPlatform, writeClosure, busybox, apps , linux_vdso, benchmark, syscall, }: let etc = lib.fileset.toSource { @@ -13,7 +13,7 @@ let ++ lib.optionals (apps != null) [ apps.package ] ++ lib.optionals (benchmark != null) [ benchmark.package ] ++ lib.optionals (syscall != null) [ syscall.package ]; -in stdenv.mkDerivation { +in stdenvNoCC.mkDerivation { name = "initramfs"; buildCommand = '' mkdir -p $out/{dev,etc,root,usr,opt,tmp,var,proc,sys} diff --git a/test/nix/syscall/default.nix b/test/nix/syscall/default.nix index 949da9199..b8c51bf34 100644 --- a/test/nix/syscall/default.nix +++ b/test/nix/syscall/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, callPackage, testSuite ? "ltp", workDir ? "/tmp", smp ? 1, +{ lib, stdenvNoCC, callPackage, testSuite ? "ltp", workDir ? "/tmp", smp ? 1, }: rec { inherit testSuite; ltp = callPackage ./ltp.nix { }; @@ -8,7 +8,7 @@ path = builtins.getEnv "GVISOR_PREBUILT_DIR"; }; - package = stdenv.mkDerivation { + package = stdenvNoCC.mkDerivation { pname = "syscall_test"; version = "0.1.0"; src = lib.fileset.toSource { diff --git a/tools/docker/nix/Dockerfile b/tools/docker/nix/Dockerfile index 2c231c33c..d1352bef0 100644 --- a/tools/docker/nix/Dockerfile +++ b/tools/docker/nix/Dockerfile @@ -36,6 +36,12 @@ RUN make general_pkgs VERBOSE=0 \ && make install_host_pkgs \ && make nix_gc +# Build initramfs packages to accelerate CI workflows +# +# It could also cache `stdenvNoCC`, a fundamental and predefined build environment. +# Therefore, `make nix_gc` MUST NOT be run after this. +RUN make initramfs_pkgs VERBOSE=0 + # Clean source files RUN rm -rf /root/test