From 6dbb2f8c92195e024f0194cda86554982301b186 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sun, 30 Jul 2023 14:51:29 -0700 Subject: [PATCH] initramfs: eliminate custom $build variable Previously the initramfs required overriders to use a custom `$build` environment variable as the destination for files to be packed into an initramfs image. This commit eliminates it, so the standard $NIX_BUILD_TOP can be used instead. --- src/initramfs/default.nix | 43 ++++++++++++++++------------------- src/platform/kgpe/default.nix | 6 ++--- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/initramfs/default.nix b/src/initramfs/default.nix index 1b242b4..78259db 100644 --- a/src/initramfs/default.nix +++ b/src/initramfs/default.nix @@ -40,47 +40,44 @@ in stdenv.mkDerivation { passAsFile = [ "modulesList" ]; buildPhase = '' - mkdir build - build=$(pwd)/build - runHook preBuild - mkdir -p $build/lib/modules + mkdir -p $NIX_BUILD_TOP/lib/modules pushd ${kernel}/lib/modules/ - cat $modulesListPath | ${cpio}/bin/cpio -p -d $build/lib/modules + cat $modulesListPath | ${cpio}/bin/cpio -p -d $NIX_BUILD_TOP/lib/modules popd - mkdir -p $build/usr - ln -s bin $build/sbin - ln -s ../bin $build/usr/bin - ln -s ../sbin $build/usr/sbin + mkdir -p $NIX_BUILD_TOP/usr + ln -s bin $NIX_BUILD_TOP/sbin + ln -s ../bin $NIX_BUILD_TOP/usr/bin + ln -s ../sbin $NIX_BUILD_TOP/usr/sbin '' + lib.optionalString withBusybox '' - cp -r ${busybox}/bin $build/bin - chmod -R u+w $build/bin + cp -r ${busybox}/bin $NIX_BUILD_TOP/bin + chmod -R u+w $NIX_BUILD_TOP/bin '' + lib.optionalString (bootScript != null) '' - cp ${bootScript} $build/boot.sh - chmod +x $build/boot.sh - ln -s boot.sh $build/init - chmod +x $build/sbin/init + cp ${bootScript} $NIX_BUILD_TOP/boot.sh + chmod +x $NIX_BUILD_TOP/boot.sh + ln -s boot.sh $NIX_BUILD_TOP/init + chmod +x $NIX_BUILD_TOP/sbin/init '' + lib.optionalString withSignify '' - cp ${signify}/bin/signify $build/bin/ + cp ${signify}/bin/signify $NIX_BUILD_TOP/bin/ '' + lib.optionalString withLvm '' - cp ${lib.getBin lvm2}/bin/lvm $build/bin/ - cp ${lib.getBin lvm2}/bin/dmsetup $build/bin/ + cp ${lib.getBin lvm2}/bin/lvm $NIX_BUILD_TOP/bin/ + cp ${lib.getBin lvm2}/bin/dmsetup $NIX_BUILD_TOP/bin/ '' + lib.optionalString withCryptsetup '' - cp ${cryptsetup}/bin/cryptsetup $build/bin/ + cp ${cryptsetup}/bin/cryptsetup $NIX_BUILD_TOP/bin/ '' + lib.optionalString withKexec '' - cp ${kexec-tools}/bin/kexec $build/bin/ + cp ${kexec-tools}/bin/kexec $NIX_BUILD_TOP/bin/ '' + lib.optionalString withNvramTool '' - cp ${nvramtool}/bin/nvramtool $build/bin/ + cp ${nvramtool}/bin/nvramtool $NIX_BUILD_TOP/bin/ '' + '' runHook postBuild ''; installPhase = '' runHook preInstall - chmod -R u+w $build - pushd $build + chmod -R u+w $NIX_BUILD_TOP + pushd $NIX_BUILD_TOP ${findutils}/bin/find . | ${cpio}/bin/cpio --create -H newc -R +0:+0 > $out popd runHook postInstall diff --git a/src/platform/kgpe/default.nix b/src/platform/kgpe/default.nix index 8b0d921..ce2f056 100644 --- a/src/platform/kgpe/default.nix +++ b/src/platform/kgpe/default.nix @@ -19,9 +19,9 @@ initramfs = prev.initramfs.overrideAttrs (a: { postBuild = (a.postBuild or "") + '' - mkdir -p $build/etc - cp ${final.image.src}/src/mainboard/asus/kgpe-d16/cmos.layout $build/etc/ - cp ${final.image.src}/src/mainboard/asus/kgpe-d16/cmos.default $build/etc/ + mkdir -p $NIX_BUILD_TOP/etc + cp ${final.image.src}/src/mainboard/asus/kgpe-d16/cmos.layout $NIX_BUILD_TOP/etc/ + cp ${final.image.src}/src/mainboard/asus/kgpe-d16/cmos.default $NIX_BUILD_TOP/etc/ ''; });