-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
build-images.sh
executable file
·58 lines (52 loc) · 2.16 KB
/
build-images.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env nix-shell
#!nix-shell -p nix -p coreutils -p bash -p gh -i bash
# shellcheck shell=bash
set -xeuo pipefail
shopt -s lastpipe
build_netboot_image() {
declare -r tag=$1 channel=$2 arch=$3 tmp=$4
img=$(nix build --print-out-paths --option accept-flake-config true -L ".#packages.${arch}.netboot-nixos-${channel//./}")
kernel=$(echo "$img"/*Image)
kernelName=$(basename "$kernel")
ln -s "$kernel" "$tmp/$kernelName-$arch"
echo "$tmp/$kernelName-$arch"
ln -s "$img/initrd" "$tmp/initrd-$arch"
echo "$tmp/initrd-$arch"
sed -e "s!^kernel $kernelName!kernel https://github.com/nix-community/nixos-images/releases/download/${tag}/$kernelName-${arch}!" \
-e "s!^initrd initrd!initrd https://github.com/nix-community/nixos-images/releases/download/${tag}/initrd-${arch}!" \
-e "s!initrd=initrd!initrd=initrd-${arch}!" \
<"$img/netboot.ipxe" \
>"$tmp/netboot-$arch.ipxe"
echo "$tmp/netboot-$arch.ipxe"
}
build_kexec_installer() {
declare -r channel=$1 arch=$2 tmp=$3 variant=$4
out=$(nix build --print-out-paths --option accept-flake-config true -L ".#packages.${arch}.kexec-installer-nixos-${channel}${variant}")
echo "$out/nixos-kexec-installer${variant}-$arch.tar.gz"
}
build_image_installer() {
declare -r channel=$1 arch=$2 tmp=$3
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"
}
main() {
declare -r tag=${1:-nixos-unstable} arch=${2:-x86_64-linux}
tmp="$(mktemp -d)"
trap 'rm -rf -- "$tmp"' EXIT
(
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
for asset in "${assets[@]}"; do
pushd "$(dirname "$asset")"
popd
done
if ! gh release view "$tag"; then
gh release create --title "$tag (build $(date +"%Y-%m-%d"))" "$tag"
fi
gh release upload --clobber "$tag" "${assets[@]}"
}
main "$@"