1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-25 03:17:13 +00:00
nixpkgs/pkgs/build-support/kernel/make-initrd.nix

53 lines
1.8 KiB
Nix
Raw Normal View History

# Create an initial ramdisk containing the closure of the specified
# file system objects. An initial ramdisk is used during the initial
# stages of booting a Linux system. It is loaded by the boot loader
# along with the kernel image. It's supposed to contain everything
# (such as kernel modules) necessary to allow us to mount the root
# file system. Once the root file system is mounted, the `real' boot
# script can be called.
#
# An initrd is really just a gzipped cpio archive.
#
# Symlinks are created for each top-level file system object. E.g.,
# `contents = {object = ...; symlink = /init;}' is a typical
# argument.
2019-10-11 16:11:19 +01:00
{ stdenvNoCC, perl, cpio, contents, ubootTools
, name ? "initrd"
, compressor ? "gzip -9n"
, prepend ? []
, lib
2017-06-26 23:58:21 +01:00
}:
2019-10-11 16:11:19 +01:00
let
# !!! Move this into a public lib function, it is probably useful for others
2019-10-11 16:11:19 +01:00
toValidStoreName = x: with builtins;
lib.concatStringsSep "-" (filter (x: !(isList x)) (split "[^a-zA-Z0-9_=.?-]+" x));
2019-10-11 16:11:19 +01:00
in stdenvNoCC.mkDerivation rec {
inherit name;
builder = ./make-initrd.sh;
2019-10-11 16:11:19 +01:00
makeUInitrd = stdenvNoCC.hostPlatform.platform.kernelTarget == "uImage";
nativeBuildInputs = [ perl cpio ]
2019-10-11 16:11:19 +01:00
++ stdenvNoCC.lib.optional makeUInitrd ubootTools;
# !!! should use XML.
objects = map (x: x.object) contents;
symlinks = map (x: x.symlink) contents;
suffices = map (x: if x ? suffix then x.suffix else "none") contents;
# For obtaining the closure of `contents'.
# Note: we don't use closureInfo yet, as that won't build with nix-1.x.
# See #36268.
exportReferencesGraph =
2019-10-11 16:11:19 +01:00
lib.zipListsWith
(x: i: [("closure-${toValidStoreName (baseNameOf x.symlink)}-${toString i}") x.object])
contents
(lib.range 0 (lib.length contents - 1));
pathsFromGraph = ./paths-from-graph.pl;
inherit compressor prepend;
}