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.
75for i in $(< $closureInfo/store-paths); do
76 addPath "${i:1}" "$i"
77done
78
79
80# Also include a manifest of the closures in a format suitable for
81# nix-store --load-db.
82if [[ ${#objects[*]} != 0 ]]; then
83 cp $closureInfo/registration nix-path-registration
84 addPath "nix-path-registration" "nix-path-registration"
85fi
86
87
88# Add symlinks to the top-level store objects.
89for ((n = 0; n < ${#objects[*]}; n++)); do
90 object=${objects[$n]}
91 symlink=${symlinks[$n]}
92 if test "$symlink" != "none"; then
93 mkdir -p $(dirname ./$symlink)
94 ln -s $object ./$symlink
95 addPath "$symlink" "./$symlink"
96 fi
97done
98
99mkdir -p $out/iso
100
101xorriso="xorriso
102 -as mkisofs
103 -iso-level 3
104 -volid ${volumeID}
105 -appid nixos
106 -publisher nixos
107 -graft-points
108 -full-iso9660-filenames
109 ${isoBootFlags}
110 ${usbBootFlags}
111 ${efiBootFlags}
112 -r
113 -path-list pathlist
114 --sort-weight 0 /
115 --sort-weight 1 /isolinux" # Make sure isolinux is near the beginning of the ISO
116
117$xorriso -output $out/iso/$isoName
118
119if test -n "$usbBootable"; then
120 echo "Making image hybrid..."
121 if test -n "$efiBootable"; then
122 isohybrid --uefi $out/iso/$isoName
123 else
124 isohybrid $out/iso/$isoName
125 fi
126fi
127
128if test -n "$compressImage"; then
129 echo "Compressing image..."
130 bzip2 $out/iso/$isoName
131fi
132
133mkdir -p $out/nix-support
134echo $system > $out/nix-support/system
135echo "file iso $out/iso/$isoName" >> $out/nix-support/hydra-build-products