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" 51fi 52 53if test -n "$usbBootable"; then 54 usbBootFlags="-isohybrid-mbr ${isohybridMbrImage}" 55fi 56 57if test -n "$efiBootable"; then 58 efiBootFlags="-eltorito-alt-boot 59 -e $efiBootImage 60 -no-emul-boot 61 -isohybrid-gpt-basdat" 62fi 63 64touch pathlist 65 66 67# Add the individual files. 68for ((i = 0; i < ${#targets_[@]}; i++)); do 69 stripSlash "${targets_[$i]}" 70 addPath "$res" "${sources_[$i]}" 71done 72 73 74# Add the closures of the top-level store objects. 75storePaths=$(perl $pathsFromGraph closure-*) 76for i in $storePaths; 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 [ -n "$object" ]; then 84 printRegistration=1 perl $pathsFromGraph closure-* > 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 102xorriso="xorriso 103 -as mkisofs 104 -iso-level 3 105 -volid ${volumeID} 106 -appid nixos 107 -publisher nixos 108 -graft-points 109 -full-iso9660-filenames 110 ${isoBootFlags} 111 ${usbBootFlags} 112 ${efiBootFlags} 113 -r 114 -path-list pathlist 115 --sort-weight 0 / 116 --sort-weight 1 /isolinux" # Make sure isolinux is near the beginning of the ISO 117 118$xorriso -output $out/iso/$isoName 119 120if test -n "$usbBootable"; then 121 echo "Making image hybrid..." 122 if test -n "$efiBootable"; then 123 isohybrid --uefi $out/iso/$isoName 124 else 125 isohybrid $out/iso/$isoName 126 fi 127fi 128 129if test -n "$compressImage"; then 130 echo "Compressing image..." 131 bzip2 $out/iso/$isoName 132fi 133 134mkdir -p $out/nix-support 135echo $system > $out/nix-support/system