nixos-images/build-images.sh

58 lines
2 KiB
Bash
Raw Normal View History

2021-06-10 08:10:06 +02:00
#!/usr/bin/env nix-shell
2022-12-16 15:27:57 +01:00
#!nix-shell -p nix -p coreutils -p bash -p gh -i bash
2021-06-10 09:30:10 +02:00
# shellcheck shell=bash
2021-06-10 08:10:06 +02:00
set -xeuo pipefail
shopt -s lastpipe
2021-06-10 08:10:06 +02:00
build_netboot_image() {
2021-06-10 09:30:10 +02:00
declare -r tag=$1 arch=$2 tmp=$3
2023-08-04 22:47:00 +02:00
img=$(nix build --print-out-paths --option accept-flake-config true -L ".#packages.${arch}.netboot-${tag//./}")
2023-08-04 23:40:01 +02:00
kernel=$(echo "$img"/*Image)
kernelName=$(basename "$kernel")
ln -s "$kernel" "$tmp/$kernelName-$arch"
echo "$tmp/$kernelName-$arch"
2021-06-12 09:00:47 +02:00
ln -s "$img/initrd" "$tmp/initrd-$arch"
2021-06-10 09:02:41 +02:00
echo "$tmp/initrd-$arch"
2023-08-04 23:40:01 +02:00
sed -e "s!^kernel $kernelName!kernel https://github.com/nix-community/nixos-images/releases/download/${tag}/$kernelName-${arch}!" \
2021-06-13 09:04:19 +02:00
-e "s!^initrd initrd!initrd https://github.com/nix-community/nixos-images/releases/download/${tag}/initrd-${arch}!" \
2021-06-16 21:48:38 +02:00
-e "s!initrd=initrd!initrd=initrd-${arch}!" \
2023-08-04 22:47:00 +02:00
<"$img/netboot.ipxe" \
>"$tmp/netboot-$arch.ipxe"
2021-06-12 09:00:47 +02:00
echo "$tmp/netboot-$arch.ipxe"
2021-06-10 08:10:06 +02:00
}
2022-09-04 14:57:14 +02:00
build_kexec_installer() {
declare -r tag=$1 arch=$2 tmp=$3 variant=$4
2023-08-04 22:47:00 +02:00
out=$(nix build --print-out-paths --option accept-flake-config true -L ".#packages.${arch}.kexec-installer-${tag//./}${variant}")
2023-05-07 21:06:12 +02:00
echo "$out/nixos-kexec-installer${variant}-$arch.tar.gz"
2022-09-04 14:57:14 +02:00
}
build_image_installer() {
declare -r tag=$1 arch=$2 tmp=$3
out=$(nix build --print-out-paths --option accept-flake-config true -L ".#packages.${arch}.image-installer-${tag//./}${variant}")
echo "$out/iso/nixos-installer-${arch}.iso"
}
2021-06-10 08:10:06 +02:00
main() {
2021-06-10 09:30:10 +02:00
declare -r tag=${1:-nixos-unstable} arch=${2:-x86_64-linux}
2021-06-10 08:10:06 +02:00
tmp="$(mktemp -d)"
trap 'rm -rf -- "$tmp"' EXIT
(
build_kexec_installer "$tag" "$arch" "$tmp" ""
build_kexec_installer "$tag" "$arch" "$tmp" "-noninteractive"
2021-06-10 10:06:41 +02:00
build_netboot_image "$tag" "$arch" "$tmp"
build_image_installer "$tag" "$arch" "$tmp"
) | readarray -t assets
2021-06-10 08:10:06 +02:00
for asset in "${assets[@]}"; do
2021-06-10 09:30:10 +02:00
pushd "$(dirname "$asset")"
2021-06-10 08:10:06 +02:00
popd
done
2023-08-04 22:47:00 +02:00
if ! gh release view "$tag"; then
gh release create --title "$tag (build $(date +"%Y-%m-%d"))" "$tag"
fi
gh release upload --clobber "$tag" "${assets[@]}"
2021-06-10 08:10:06 +02:00
}
main "$@"