@ -12,6 +12,31 @@
# files which should be included in the initrd
# files which should be included in the initrd
, modules ? [ ]
, 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.
#
, contents ? { }
# cause usr/{bin,sbin} to be symlinks to {bin/sbin}
, withMergedUsr ? true
# cause sbin to be a symlink to bin
, withMergedBinSbin ? true
, withBusybox ? true
, withBusybox ? true
, withSignify ? true
, withSignify ? true
# Inclusion of these is temporarily disabled. I had a bunch of
# Inclusion of these is temporarily disabled. I had a bunch of
@ -31,46 +56,55 @@ let
nvramtool = nixpkgsOnBuildForHost . pkgsStatic . nvramtool . overrideAttrs ( a : {
nvramtool = nixpkgsOnBuildForHost . pkgsStatic . nvramtool . overrideAttrs ( a : {
NIX_CFLAGS_COMPILE = " - D _ _ G L I B C _ _ " ;
NIX_CFLAGS_COMPILE = " - D _ _ G L I B C _ _ " ;
} ) ;
} ) ;
contents' = ( lib . pipe modules [
( map ( m : let name = " ${ kernel . version } / k e r n e l / ${ m } " ;
in {
name = " l i b / m o d u l e s / ${ name } " ; # dest
value = " ${ kernel } / l i b / m o d u l e s / ${ name } " ; # source
} ) )
lib . listToAttrs
] ) // lib . optionalAttrs withBusybox {
" b i n " = " ${ busybox } / b i n / " ;
} // lib . optionalAttrs withSignify {
" b i n / s i g n i f y " = " ${ signify } / b i n / s i g n i f y " ;
} // lib . optionalAttrs withLvm {
" b i n / l v m " = " ${ lib . getBin lvm2 } / b i n / l v m " ;
" b i n / d m s e t u p " = " ${ lib . getBin lvm2 } / b i n / d m s e t u p " ;
} // lib . optionalAttrs withCryptsetup {
" b i n / c r y p t s e t u p " = " ${ cryptsetup } / b i n / c r y p t s e t u p " ;
} // lib . optionalAttrs withKexec {
" b i n / k e x e c " = " ${ kexec-tools } / b i n / k e x e c " ;
} // lib . optionalAttrs withNvramTool {
" b i n / n v r a m t o o l " = " ${ nvramtool } / b i n / n v r a m t o o l " ;
} // lib . optionalAttrs ( bootScript != null ) {
" s b i n / i n i t " = " ${ bootScript } " ;
} // contents ;
in stdenv . mkDerivation {
in stdenv . mkDerivation {
name = " i n i t r a m f s . c p i o " ;
name = " i n i t r a m f s . c p i o " ;
dontUnpack = true ;
dontUnpack = true ;
dontFixup = true ;
dontFixup = true ;
modulesList = ( lib . concatMapStringsSep " \n " ( m : " ${ kernel . version } / k e r n e l / " + m ) modules ) + " \n " ;
passAsFile = [ " m o d u l e s L i s t " ] ;
buildPhase = ''
buildPhase = ''
runHook preBuild
runHook preBuild
'' + l i b . o p t i o n a l S t r i n g w i t h M e r g e d B i n S b i n ''
mkdir - p $ NIX_BUILD_TOP/lib/modules
ln - s bin sbin
pushd $ { kernel } /lib/modules /
'' + l i b . o p t i o n a l S t r i n g w i t h M e r g e d U s r ''
cat $ modulesListPath | $ { cpio } /bin/cpio - p - d $ NIX_BUILD_TOP/lib/modules
mkdir - p usr
popd
ln - s ../bin usr/bin
ln - s ../sbin usr/sbin
mkdir - p $ NIX_BUILD_TOP/usr
'' + ( l i b . p i p e c o n t e n t s ' [
ln - s bin $ NIX_BUILD_TOP/sbin
( lib . mapAttrsToList ( dest : src :
ln - s ../bin $ NIX_BUILD_TOP/usr/bin
if lib . hasSuffix " / " src then ''
ln - s ../sbin $ NIX_BUILD_TOP/usr/sbin
mkdir - p $ { lib . escapeShellArg ( builtins . dirOf dest ) }
'' + l i b . o p t i o n a l S t r i n g w i t h B u s y b o x ''
cp - Tr $ { lib . escapeShellArg src } $ { lib . escapeShellArg dest }
cp - r $ { busybox } /bin $ NIX_BUILD_TOP/bin
chmod - R u + w $ { lib . escapeShellArg dest }
chmod - R u + w $ NIX_BUILD_TOP/bin
'' e l s e ''
'' + l i b . o p t i o n a l S t r i n g ( b o o t S c r i p t ! = n u l l ) ''
install - vDT $ { lib . escapeShellArg src } $ { lib . escapeShellArg dest }
cp $ { bootScript } $ NIX_BUILD_TOP/boot.sh
'' ) )
chmod + x $ NIX_BUILD_TOP/boot.sh
lib . concatStrings
ln - s boot . sh $ NIX_BUILD_TOP/init
] ) +
chmod + x $ NIX_BUILD_TOP/sbin/init
''
'' + l i b . o p t i o n a l S t r i n g w i t h S i g n i f y ''
cp $ { signify } /bin/signify $ NIX_BUILD_TOP/bin /
'' + l i b . o p t i o n a l S t r i n g w i t h L v m ''
cp $ { lib . getBin lvm2 } /bin/lvm $ NIX_BUILD_TOP/bin /
cp $ { lib . getBin lvm2 } /bin/dmsetup $ NIX_BUILD_TOP/bin /
'' + l i b . o p t i o n a l S t r i n g w i t h C r y p t s e t u p ''
cp $ { cryptsetup } /bin/cryptsetup $ NIX_BUILD_TOP/bin /
'' + l i b . o p t i o n a l S t r i n g w i t h K e x e c ''
cp $ { kexec-tools } /bin/kexec $ NIX_BUILD_TOP/bin /
'' + l i b . o p t i o n a l S t r i n g w i t h N v r a m T o o l ''
cp $ { nvramtool } /bin/nvramtool $ NIX_BUILD_TOP/bin /
'' + ''
runHook postBuild
runHook postBuild
'' ;
'' ;