at 23.11-pre 3.6 kB view raw
1# Remove the initial slash from a path, since genisofs likes it that way. 2stripSlash() { 3 res="$1" 4 if test "${res:0:1}" = /; then res=${res:1}; fi 5} 6 7# Escape potential equal signs (=) with backslash (\=) 8escapeEquals() { 9 echo "$1" | sed -e 's/\\/\\\\/g' -e 's/=/\\=/g' 10} 11 12# Queues an file/directory to be placed on the ISO. 13# An entry consists of a local source path (2) and 14# a destination path on the ISO (1). 15addPath() { 16 target="$1" 17 source="$2" 18 echo "$(escapeEquals "$target")=$(escapeEquals "$source")" >> pathlist 19} 20 21stripSlash "$bootImage"; bootImage="$res" 22 23 24if test -n "$bootable"; then 25 26 # The -boot-info-table option modifies the $bootImage file, so 27 # find it in `contents' and make a copy of it (since the original 28 # is read-only in the Nix store...). 29 for ((i = 0; i < ${#targets[@]}; i++)); do 30 stripSlash "${targets[$i]}" 31 if test "$res" = "$bootImage"; then 32 echo "copying the boot image ${sources[$i]}" 33 cp "${sources[$i]}" boot.img 34 chmod u+w boot.img 35 sources[$i]=boot.img 36 fi 37 done 38 39 isoBootFlags="-eltorito-boot ${bootImage} 40 -eltorito-catalog .boot.cat 41 -no-emul-boot -boot-load-size 4 -boot-info-table 42 --sort-weight 1 /isolinux" # Make sure isolinux is near the beginning of the ISO 43fi 44 45if test -n "$usbBootable"; then 46 usbBootFlags="-isohybrid-mbr ${isohybridMbrImage}" 47fi 48 49if test -n "$efiBootable"; then 50 efiBootFlags="-eltorito-alt-boot 51 -e $efiBootImage 52 -no-emul-boot 53 -isohybrid-gpt-basdat" 54fi 55 56touch pathlist 57 58 59# Add the individual files. 60for ((i = 0; i < ${#targets[@]}; i++)); do 61 stripSlash "${targets[$i]}" 62 addPath "$res" "${sources[$i]}" 63done 64 65 66# Add the closures of the top-level store objects. 67for i in $(< $closureInfo/store-paths); do 68 addPath "${i:1}" "$i" 69done 70 71 72# Also include a manifest of the closures in a format suitable for 73# nix-store --load-db. 74if [[ ${#objects[*]} != 0 ]]; then 75 cp $closureInfo/registration nix-path-registration 76 addPath "nix-path-registration" "nix-path-registration" 77fi 78 79 80# Add symlinks to the top-level store objects. 81for ((n = 0; n < ${#objects[*]}; n++)); do 82 object=${objects[$n]} 83 symlink=${symlinks[$n]} 84 if test "$symlink" != "none"; then 85 mkdir -p $(dirname ./$symlink) 86 ln -s $object ./$symlink 87 addPath "$symlink" "./$symlink" 88 fi 89done 90 91mkdir -p $out/iso 92 93# daed2280-b91e-42c0-aed6-82c825ca41f3 is an arbitrary namespace, to prevent 94# independent applications from generating the same UUID for the same value. 95# (the chance of that being problematic seem pretty slim here, but that's how 96# version-5 UUID's work) 97xorriso="xorriso 98 -boot_image any gpt_disk_guid=$(uuid -v 5 daed2280-b91e-42c0-aed6-82c825ca41f3 $out | tr -d -) 99 -volume_date all_file_dates =$SOURCE_DATE_EPOCH 100 -as mkisofs 101 -iso-level 3 102 -volid ${volumeID} 103 -appid nixos 104 -publisher nixos 105 -graft-points 106 -full-iso9660-filenames 107 -joliet 108 ${isoBootFlags} 109 ${usbBootFlags} 110 ${efiBootFlags} 111 -r 112 -path-list pathlist 113 --sort-weight 0 / 114" 115 116$xorriso -output $out/iso/$isoName 117 118if test -n "$compressImage"; then 119 echo "Compressing image..." 120 zstd -T$NIX_BUILD_CORES --rm $out/iso/$isoName 121fi 122 123mkdir -p $out/nix-support 124echo $system > $out/nix-support/system 125 126if test -n "$compressImage"; then 127 echo "file iso $out/iso/$isoName.zst" >> $out/nix-support/hydra-build-products 128else 129 echo "file iso $out/iso/$isoName" >> $out/nix-support/hydra-build-products 130fi