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