Merge pull request #305886 from wegank/ocaml-jane-street-old-drop
[NixPkgs.git] / nixos / lib / make-iso9660-image.sh
blob5881195e461f8829d4cf5103891fad7d73420bc1
1 # Remove the initial slash from a path, since genisofs likes it that way.
2 stripSlash() {
3 res="$1"
4 if test "${res:0:1}" = /; then res=${res:1}; fi
7 # Escape potential equal signs (=) with backslash (\=)
8 escapeEquals() {
9 echo "$1" | sed -e 's/\\/\\\\/g' -e 's/=/\\=/g'
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).
15 addPath() {
16 target="$1"
17 source="$2"
18 echo "$(escapeEquals "$target")=$(escapeEquals "$source")" >> pathlist
21 stripSlash "$bootImage"; bootImage="$res"
24 if test -n "$bootable"; then
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
37 done
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
45 if test -n "$usbBootable"; then
46 usbBootFlags="-isohybrid-mbr ${isohybridMbrImage}"
49 if test -n "$efiBootable"; then
50 efiBootFlags="-eltorito-alt-boot
51 -e $efiBootImage
52 -no-emul-boot
53 -isohybrid-gpt-basdat"
56 touch pathlist
59 # Add the individual files.
60 for ((i = 0; i < ${#targets[@]}; i++)); do
61 stripSlash "${targets[$i]}"
62 addPath "$res" "${sources[$i]}"
63 done
66 # Add the closures of the top-level store objects.
67 for i in $(< $closureInfo/store-paths); do
68 addPath "${i:1}" "$i"
69 done
71 # If needed, build a squashfs and add that
72 if [[ -n "$squashfsCommand" ]]; then
73 (out="nix-store.squashfs" eval "$squashfsCommand")
74 addPath "nix-store.squashfs" "nix-store.squashfs"
77 # Also include a manifest of the closures in a format suitable for
78 # nix-store --load-db.
79 if [[ ${#objects[*]} != 0 ]]; then
80 cp $closureInfo/registration nix-path-registration
81 addPath "nix-path-registration" "nix-path-registration"
85 # Add symlinks to the top-level store objects.
86 for ((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"
94 done
96 mkdir -p $out/iso
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)
102 xorriso="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}
117 -path-list pathlist
118 --sort-weight 0 /
121 $xorriso -output $out/iso/$isoName
123 if test -n "$compressImage"; then
124 echo "Compressing image..."
125 zstd -T$NIX_BUILD_CORES --rm $out/iso/$isoName
128 mkdir -p $out/nix-support
129 echo $system > $out/nix-support/system
131 if test -n "$compressImage"; then
132 echo "file iso $out/iso/$isoName.zst" >> $out/nix-support/hydra-build-products
133 else
134 echo "file iso $out/iso/$isoName" >> $out/nix-support/hydra-build-products