nixos-images/build-images.sh

59 lines
2.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() {
2024-06-07 10:25:52 +02:00
declare -r tag=$1 channel=$2 arch=$3 tmp=$4
2024-06-07 14:09:13 +02:00
img=$(nix build --print-out-paths --option accept-flake-config true -L ".#packages.${arch}.netboot-nixos-${channel//./}")
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() {
2024-06-07 10:25:52 +02:00
declare -r channel=$1 arch=$2 tmp=$3 variant=$4
2024-06-07 14:09:13 +02:00
out=$(nix build --print-out-paths --option accept-flake-config true -L ".#packages.${arch}.kexec-installer-nixos-${channel}${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() {
2024-06-07 10:25:52 +02:00
declare -r channel=$1 arch=$2 tmp=$3
2024-06-07 14:09:13 +02:00
out=$(nix build --print-out-paths --option accept-flake-config true -L ".#packages.${arch}.image-installer-nixos-${channel//./}")
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
(
2024-06-07 10:25:52 +02:00
channel=$(if [[ "$tag" == nixos-unstable ]]; then echo "unstable"; else echo "stable"; fi)
build_kexec_installer "$channel" "$arch" "$tmp" ""
build_kexec_installer "$channel" "$arch" "$tmp" "-noninteractive"
build_netboot_image "$tag" "$channel" "$arch" "$tmp"
build_image_installer "$channel" "$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 "$@"