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