1{
2 lib,
3 stdenv,
4 callPackage,
5 closureInfo,
6 xorriso,
7 syslinux,
8 libossp_uuid,
9 squashfsTools,
10
11 # The file name of the resulting ISO image.
12 isoName ? "cd.iso",
13
14 # The files and directories to be placed in the ISO file system.
15 # This is a list of attribute sets {source, target} where `source'
16 # is the file system object (regular file or directory) to be
17 # grafted in the file system at path `target'.
18 contents,
19
20 # In addition to `contents', the closure of the store paths listed
21 # in `storeContents' are also placed in the Nix store of the CD.
22 # This is a list of attribute sets {object, symlink} where `object'
23 # is a store path whose closure will be copied, and `symlink' is a
24 # symlink to `object' that will be added to the CD.
25 storeContents ? [ ],
26
27 # In addition to `contents', the closure of the store paths listed
28 # in `squashfsContents' is compressed as squashfs and the result is
29 # placed in /nix-store.squashfs on the CD.
30 # FIXME: This is a performance optimization to avoid Hydra copying
31 # the squashfs between builders and should be removed when Hydra
32 # is smarter about scheduling.
33 squashfsContents ? [ ],
34
35 # Compression settings for squashfs
36 squashfsCompression ? "xz -Xdict-size 100%",
37
38 # Whether this should be an El-Torito bootable CD.
39 bootable ? false,
40
41 # Whether this should be an efi-bootable El-Torito CD.
42 efiBootable ? false,
43
44 # Whether this should be an hybrid CD (bootable from USB as well as CD).
45 usbBootable ? false,
46
47 # The path (in the ISO file system) of the boot image.
48 bootImage ? "",
49
50 # The path (in the ISO file system) of the efi boot image.
51 efiBootImage ? "",
52
53 # The path (outside the ISO file system) of the isohybrid-mbr image.
54 isohybridMbrImage ? "",
55
56 # Whether to compress the resulting ISO image with zstd.
57 compressImage ? false,
58 zstd,
59
60 # The volume ID.
61 volumeID ? "",
62}:
63
64assert bootable -> bootImage != "";
65assert efiBootable -> efiBootImage != "";
66assert usbBootable -> isohybridMbrImage != "";
67
68let
69 needSquashfs = squashfsContents != [ ];
70 makeSquashfsDrv = callPackage ./make-squashfs.nix {
71 storeContents = squashfsContents;
72 comp = squashfsCompression;
73 };
74in
75stdenv.mkDerivation {
76 name = isoName;
77 __structuredAttrs = true;
78
79 # the image will be self-contained so we can drop references
80 # to the closure that was used to build it
81 unsafeDiscardReferences.out = true;
82
83 buildCommandPath = ./make-iso9660-image.sh;
84 nativeBuildInputs = [
85 xorriso
86 syslinux
87 zstd
88 libossp_uuid
89 ]
90 ++ lib.optionals needSquashfs makeSquashfsDrv.nativeBuildInputs;
91
92 inherit
93 isoName
94 bootable
95 bootImage
96 compressImage
97 volumeID
98 efiBootImage
99 efiBootable
100 isohybridMbrImage
101 usbBootable
102 ;
103
104 sources = map (x: x.source) contents;
105 targets = map (x: x.target) contents;
106
107 objects = map (x: x.object) storeContents;
108 symlinks = map (x: x.symlink) storeContents;
109
110 squashfsCommand = lib.optionalString needSquashfs makeSquashfsDrv.buildCommand;
111
112 # For obtaining the closure of `storeContents'.
113 closureInfo = closureInfo { rootPaths = map (x: x.object) storeContents; };
114}