at master 3.8 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# If needed, build a squashfs and add that 72if [[ -n "$squashfsCommand" ]]; then 73 (out="nix-store.squashfs" eval "$squashfsCommand") 74 addPath "nix-store.squashfs" "nix-store.squashfs" 75fi 76 77# Also include a manifest of the closures in a format suitable for 78# nix-store --load-db. 79if [[ ${#objects[*]} != 0 ]]; then 80 cp $closureInfo/registration nix-path-registration 81 addPath "nix-path-registration" "nix-path-registration" 82fi 83 84 85# Add symlinks to the top-level store objects. 86for ((n = 0; n < ${#objects[*]}; n++)); do 87 object=${objects[$n]} 88 symlink=${symlinks[$n]} 89 if test "$symlink" != "none"; then 90 mkdir -p $(dirname ./$symlink) 91 ln -s $object ./$symlink 92 addPath "$symlink" "./$symlink" 93 fi 94done 95 96mkdir -p $out/iso 97 98# daed2280-b91e-42c0-aed6-82c825ca41f3 is an arbitrary namespace, to prevent 99# independent applications from generating the same UUID for the same value. 100# (the chance of that being problematic seem pretty slim here, but that's how 101# version-5 UUID's work) 102xorriso="xorriso 103 -boot_image any gpt_disk_guid=$(uuid -v 5 daed2280-b91e-42c0-aed6-82c825ca41f3 $out | tr -d -) 104 -volume_date all_file_dates =$SOURCE_DATE_EPOCH 105 -as mkisofs 106 -iso-level 3 107 -volid ${volumeID} 108 -appid nixos 109 -publisher nixos 110 -graft-points 111 -full-iso9660-filenames 112 -joliet 113 ${isoBootFlags} 114 ${usbBootFlags} 115 ${efiBootFlags} 116 -r 117 -path-list pathlist 118 --sort-weight 0 / 119" 120 121$xorriso -output $out/iso/$isoName 122 123if test -n "$compressImage"; then 124 echo "Compressing image..." 125 zstd -T$NIX_BUILD_CORES --rm $out/iso/$isoName 126fi 127 128mkdir -p $out/nix-support 129echo $system > $out/nix-support/system 130 131if test -n "$compressImage"; then 132 echo "file iso $out/iso/$isoName.zst" >> $out/nix-support/hydra-build-products 133else 134 echo "file iso $out/iso/$isoName" >> $out/nix-support/hydra-build-products 135fi