nixos-images/build-images.sh

51 lines
1.8 KiB
Bash
Raw Permalink Normal View History

2021-06-10 08:10:06 +02:00
#!/usr/bin/env nix-shell
2021-06-10 10:06:41 +02:00
#!nix-shell -p nixos-generators -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
build_netboot_image() {
2021-06-10 09:30:10 +02:00
declare -r tag=$1 arch=$2 tmp=$3
2021-06-10 08:10:06 +02:00
img=$(nix-build --no-out-link -I "nixpkgs=https://github.com/NixOS/nixpkgs/archive/${tag}.tar.gz" '<nixpkgs/nixos/release.nix>' -A "netboot.$arch")
2021-06-12 09:00:47 +02:00
ln -s "$img/bzImage" "$tmp/bzImage-$arch"
2021-06-10 09:02:41 +02:00
echo "$tmp/bzImage-$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"
2021-06-13 09:04:19 +02:00
sed -e "s!^kernel bzImage!kernel https://github.com/nix-community/nixos-images/releases/download/${tag}/bzImage-${arch}!" \
-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}!" \
2021-06-13 09:04:19 +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
}
2021-06-10 10:06:41 +02:00
build_kexec_bundle() {
declare -r tag=$1 arch=$2 tmp=$3
# the default configuration conflicts with the kexec bundle configuration
echo "{}" > "$tmp/config.nix"
nixos-generate -o "$tmp/kexec-bundle-$arch" -c "$tmp/config.nix" -f kexec-bundle -I "nixpkgs=https://github.com/NixOS/nixpkgs/archive/${tag}.tar.gz"
echo "$tmp/kexec-bundle-$arch"
}
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
2021-06-10 10:06:41 +02:00
readarray -t assets < <(
build_kexec_bundle "$tag" "$arch" "$tmp"
build_netboot_image "$tag" "$arch" "$tmp"
)
2021-06-10 08:10:06 +02:00
for asset in "${assets[@]}"; do
2021-06-10 09:30:10 +02:00
pushd "$(dirname "$asset")"
sha256sum "$(basename "$asset")" >> "$TMP/sha256sums"
2021-06-10 08:10:06 +02:00
popd
done
assets+=("$TMP/sha256sums")
# Since we cannot atomically update a release, we delete the old one before
gh release delete "$tag" </dev/null || true
gh release create --title "$tag (build $(date +"%Y-%m-%d"))" "$tag" "${assets[@]}" </dev/null
}
main "$@"