From 1697879c6496e644a337cd7a9c017f892dc885b7 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 6 Jul 2024 19:36:47 +0200 Subject: [PATCH] Cache `nixpkgs` locally --- archiso/scripts/build.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/archiso/scripts/build.sh b/archiso/scripts/build.sh index 72611308..cf3e95d7 100755 --- a/archiso/scripts/build.sh +++ b/archiso/scripts/build.sh @@ -1,13 +1,24 @@ #!/bin/bash -contextRoot="$(mktemp -d)"; -root="$contextRoot/airootfs"; -rootHome="$root/root"; -nixDir="$root/nix/var/nix/profiles/per-user/root/channels/nixpkgs"; +overlayDir="$(mktemp -d)"; +upperDir="$(mktemp -d)"; +workDir="$(mktemp -d)"; +cacheRoot=~/.cache/archiso-valhalla; +nixCache="$cacheRoot/nixpkgs"; +root="airootfs"; +rootHome="$overlayDir/$root/root"; profileDir="/mnt/archiso-valhalla"; +nixDir="$profileDir/$root/nix/var/nix/profiles/per-user/root/channels/nixpkgs"; mkdir -p "$rootHome"; git clone .. "$rootHome/PortValhalla"; -git clone https://github.com/NixOS/nixpkgs.git --depth=1 -b nixos-24.05 "$nixDir"; -rm -rf "$nixDir/.git"; -sudo mount --mkdir -t overlay overlay -o lowerdir=.:"$contextRoot" "$profileDir"; + +if [ ! -d "$nixCache" ]; then + mkdir -p "$nixCache" + git clone https://github.com/NixOS/nixpkgs.git --depth=1 -b nixos-24.05 "$nixCache"; + rm -rf "$nixCache/.git"; +fi; + +sudo mount --mkdir -t overlay overlay -o lowerdir=.:"$overlayDir",upperdir="$upperDir",workdir="$workDir" "$profileDir"; +sudo mount --mkdir --bind "$nixCache" "$nixDir"; sudo mkarchiso "$@" "$profileDir"; +sudo umount "$nixDir"; sudo umount "$profileDir";