|
|
|
@ -5,39 +5,17 @@
|
|
|
|
|
{ lib
|
|
|
|
|
, nixpkgsOnBuildForHost
|
|
|
|
|
, nixpkgsOnBuildForBuild
|
|
|
|
|
, kernel
|
|
|
|
|
, bootScript ? ../boot.sh # symlinked to /init if non-null
|
|
|
|
|
|
|
|
|
|
# a list of paths (relative to ${kernel}/lib/modules/*/kernel) to modules .ko
|
|
|
|
|
# files which should be included in the initrd
|
|
|
|
|
, modules ? [ ]
|
|
|
|
|
|
|
|
|
|
# An attrset containing additional files to include in the initramfs
|
|
|
|
|
# image. Each attrname in this set is a path relative to the root
|
|
|
|
|
# of the initramfs (e.g. "bin/signify") and the corresponding value is
|
|
|
|
|
# the file to be copied to that location (e.g. "${signify}/bin/signify).
|
|
|
|
|
#
|
|
|
|
|
# - If the attrvalue has a trailing "/" then both the source and
|
|
|
|
|
# destination are considered to be directories; the source will be
|
|
|
|
|
# copied recursively, and symbolic links therein will be preserved
|
|
|
|
|
# (i.e. not dereferenced). See `withBusybox` below for an example.
|
|
|
|
|
#
|
|
|
|
|
# - If the attrvalue does NOT have a trailing "/" then both the
|
|
|
|
|
# source and destination are considered to be files. If the
|
|
|
|
|
# source is a symbolic link it will be dereferenced before copying.
|
|
|
|
|
#
|
|
|
|
|
# After copying, `chmod -R u+w` is performed, since the contents are
|
|
|
|
|
# likely to be coming from /nix/store where Nix clears the u-w bit.
|
|
|
|
|
#
|
|
|
|
|
# see six-initrd
|
|
|
|
|
, contents ? {}
|
|
|
|
|
, kernel ? null
|
|
|
|
|
, modules ? []
|
|
|
|
|
, symlinkUsrToRoot ? true
|
|
|
|
|
, symlinkSbinToBin ? true
|
|
|
|
|
|
|
|
|
|
# cause usr/{bin,sbin} to be symlinks to {bin/sbin}
|
|
|
|
|
, withMergedUsr ? true
|
|
|
|
|
|
|
|
|
|
# cause sbin to be a symlink to bin
|
|
|
|
|
, withMergedBinSbin ? true
|
|
|
|
|
, six-initrd
|
|
|
|
|
|
|
|
|
|
, withBusybox ? true
|
|
|
|
|
, withSignify ? true
|
|
|
|
|
# Inclusion of these is temporarily disabled. I had a bunch of
|
|
|
|
|
# ugly space-saving hacks that were removed during the pre-release
|
|
|
|
@ -51,21 +29,18 @@
|
|
|
|
|
}:
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
inherit (nixpkgsOnBuildForBuild) findutils cpio;
|
|
|
|
|
inherit (nixpkgsOnBuildForHost.pkgsStatic) stdenv busybox signify lvm2 cryptsetup kexec-tools;
|
|
|
|
|
inherit (nixpkgsOnBuildForHost.pkgsStatic) signify lvm2 cryptsetup kexec-tools;
|
|
|
|
|
nvramtool = nixpkgsOnBuildForHost.pkgsStatic.nvramtool.overrideAttrs(a: {
|
|
|
|
|
NIX_CFLAGS_COMPILE = "-D__GLIBC__";
|
|
|
|
|
});
|
|
|
|
|
contents' = (lib.pipe modules [
|
|
|
|
|
(map (m: let name = "${kernel.version}/kernel/${m}";
|
|
|
|
|
in {
|
|
|
|
|
name = "lib/modules/${name}"; # dest
|
|
|
|
|
value = "${kernel}/lib/modules/${name}"; # source
|
|
|
|
|
}))
|
|
|
|
|
lib.listToAttrs
|
|
|
|
|
]) // lib.optionalAttrs withBusybox {
|
|
|
|
|
"bin" = "${busybox}/bin/";
|
|
|
|
|
} // lib.optionalAttrs withSignify {
|
|
|
|
|
|
|
|
|
|
in
|
|
|
|
|
six-initrd.override {
|
|
|
|
|
inherit lib;
|
|
|
|
|
pkgsForBuild = nixpkgsOnBuildForBuild;
|
|
|
|
|
pkgsForHost = nixpkgsOnBuildForHost;
|
|
|
|
|
inherit kernel modules;
|
|
|
|
|
contents = lib.optionalAttrs withSignify {
|
|
|
|
|
"bin/signify" = "${signify}/bin/signify";
|
|
|
|
|
} // lib.optionalAttrs withLvm {
|
|
|
|
|
"bin/lvm" = "${lib.getBin lvm2}/bin/lvm";
|
|
|
|
@ -79,45 +54,4 @@ let
|
|
|
|
|
} // lib.optionalAttrs (bootScript != null) {
|
|
|
|
|
"sbin/init" = "${bootScript}";
|
|
|
|
|
} // contents;
|
|
|
|
|
|
|
|
|
|
in stdenv.mkDerivation {
|
|
|
|
|
name = "initramfs.cpio";
|
|
|
|
|
dontUnpack = true;
|
|
|
|
|
dontFixup = true;
|
|
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
|
runHook preBuild
|
|
|
|
|
'' + lib.optionalString withMergedBinSbin ''
|
|
|
|
|
ln -s bin sbin
|
|
|
|
|
'' + lib.optionalString withMergedUsr ''
|
|
|
|
|
mkdir -p usr
|
|
|
|
|
ln -s ../bin usr/bin
|
|
|
|
|
ln -s ../sbin usr/sbin
|
|
|
|
|
'' + (lib.pipe contents' [
|
|
|
|
|
(lib.mapAttrsToList (dest: src:
|
|
|
|
|
if lib.hasSuffix "/" src then ''
|
|
|
|
|
mkdir -p ${lib.escapeShellArg (builtins.dirOf dest)}
|
|
|
|
|
cp -Tr ${lib.escapeShellArg src} ${lib.escapeShellArg dest}
|
|
|
|
|
chmod -R u+w ${lib.escapeShellArg dest}
|
|
|
|
|
'' else ''
|
|
|
|
|
install -vDT ${lib.escapeShellArg src} ${lib.escapeShellArg dest}
|
|
|
|
|
''))
|
|
|
|
|
lib.concatStrings
|
|
|
|
|
]) +
|
|
|
|
|
''
|
|
|
|
|
runHook postBuild
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
|
runHook preInstall
|
|
|
|
|
chmod -R u+w $NIX_BUILD_TOP
|
|
|
|
|
pushd $NIX_BUILD_TOP
|
|
|
|
|
${findutils}/bin/find . | ${cpio}/bin/cpio --create -H newc -R +0:+0 > $out
|
|
|
|
|
popd
|
|
|
|
|
runHook postInstall
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
|
inherit modules;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|