1# Create an initial ramdisk containing the closure of the specified
2# file system objects. An initial ramdisk is used during the initial
3# stages of booting a Linux system. It is loaded by the boot loader
4# along with the kernel image. It's supposed to contain everything
5# (such as kernel modules) necessary to allow us to mount the root
6# file system. Once the root file system is mounted, the `real' boot
7# script can be called.
8#
9# An initrd is really just a gzipped cpio archive.
10#
11# Symlinks are created for each top-level file system object. E.g.,
12# `contents = {object = ...; symlink = /init;}' is a typical
13# argument.
14
15{ stdenv, perl, perlArchiveCpio, cpio, contents, ubootChooser, compressor, prepend }:
16
17let
18 inputsFun = ubootName : [perl cpio perlArchiveCpio ]
19 ++ stdenv.lib.optional (ubootName != null) [ (ubootChooser ubootName) ];
20 makeUInitrdFun = ubootName : (ubootName != null);
21in
22stdenv.mkDerivation {
23 name = "initrd";
24 builder = ./make-initrd.sh;
25 nativeBuildInputs = inputsFun stdenv.platform.uboot;
26
27 makeUInitrd = makeUInitrdFun stdenv.platform.uboot;
28
29 # !!! should use XML.
30 objects = map (x: x.object) contents;
31 symlinks = map (x: x.symlink) contents;
32 suffices = map (x: if x ? suffix then x.suffix else "none") contents;
33
34 # For obtaining the closure of `contents'.
35 exportReferencesGraph =
36 map (x: [("closure-" + baseNameOf x.symlink) x.object]) contents;
37 pathsFromGraph = ./paths-from-graph.pl;
38 cpioClean = ./cpio-clean.pl;
39
40 crossAttrs = {
41 nativeBuildInputs = inputsFun stdenv.cross.platform.uboot;
42 makeUInitrd = makeUInitrdFun stdenv.cross.platform.uboot;
43 };
44 inherit compressor prepend;
45}