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 -volume_date all_file_dates =$SOURCE_DATE_EPOCH
109 -as mkisofs
110 -iso-level 3
111 -volid ${volumeID}
112 -appid nixos
113 -publisher nixos
114 -graft-points
115 -full-iso9660-filenames
116 -joliet
117 ${isoBootFlags}
118 ${usbBootFlags}
119 ${efiBootFlags}
120 -r
121 -path-list pathlist
122 --sort-weight 0 /
123"
124
125$xorriso -output $out/iso/$isoName
126
127if test -n "$compressImage"; then
128 echo "Compressing image..."
129 zstd -T$NIX_BUILD_CORES --rm $out/iso/$isoName
130fi
131
132mkdir -p $out/nix-support
133echo $system > $out/nix-support/system
134
135if test -n "$compressImage"; then
136 echo "file iso $out/iso/$isoName.zst" >> $out/nix-support/hydra-build-products
137else
138 echo "file iso $out/iso/$isoName" >> $out/nix-support/hydra-build-products
139fi