nixos/initrd: Generic library copying

This commit is contained in:
William A. Kennington III 2015-03-28 17:15:41 -07:00
parent b1e854d660
commit 4868649f03
17 changed files with 71 additions and 77 deletions

View File

@ -23,9 +23,9 @@ in
boot.kernelParams = [ "console=ttyS0" ];
boot.initrd.extraUtilsCommands = ''
cp -v ${pkgs.gawk}/bin/gawk $out/bin/gawk
cp -v ${pkgs.gnused}/bin/sed $out/bin/gnused
cp -v ${pkgs.utillinux}/sbin/sfdisk $out/bin/sfdisk
copy_bin_and_libs ${pkgs.gawk}/bin/gawk
copy_bin_and_libs ${pkgs.gnused}/bin/sed
copy_bin_and_libs ${pkgs.utillinux}/sbin/sfdisk
cp -v ${growpart} $out/bin/growpart
'';
boot.initrd.postDeviceCommands = ''

View File

@ -98,7 +98,7 @@ in
boot.initrd.extraUtilsCommands =
''
cp ${pkgs.utillinux}/sbin/hwclock $out/bin
copy_bin_and_libs ${pkgs.utillinux}/sbin/hwclock
'';
boot.initrd.postDeviceCommands =

View File

@ -405,26 +405,16 @@ in
# copy the cryptsetup binary and it's dependencies
boot.initrd.extraUtilsCommands = ''
cp -pdv ${pkgs.cryptsetup}/sbin/cryptsetup $out/bin
cp -pdv ${pkgs.libgcrypt_1_6}/lib/libgcrypt*.so.* $out/lib
cp -pdv ${pkgs.libgpgerror}/lib/libgpg-error*.so.* $out/lib
cp -pdv ${pkgs.cryptsetup}/lib/libcryptsetup*.so.* $out/lib
cp -pdv ${pkgs.popt}/lib/libpopt*.so.* $out/lib
copy_bin_and_libs ${pkgs.cryptsetup}/bin/cryptsetup
${optionalString luks.yubikeySupport ''
cp -pdv ${pkgs.ykpers}/bin/ykchalresp $out/bin
cp -pdv ${pkgs.ykpers}/bin/ykinfo $out/bin
cp -pdv ${pkgs.openssl}/bin/openssl $out/bin
copy_bin_and_libs ${pkgs.ykpers}/bin/ykchalresp
copy_bin_and_libs ${pkgs.ykpers}/bin/ykinfo
copy_bin_and_libs ${pkgs.openssl}/bin/openssl
cc -O3 -I${pkgs.openssl}/include -L${pkgs.openssl}/lib ${./pbkdf2-sha512.c} -o $out/bin/pbkdf2-sha512 -lcrypto
strip -s $out/bin/pbkdf2-sha512
cp -pdv ${pkgs.libusb1}/lib/libusb*.so.* $out/lib
cp -pdv ${pkgs.ykpers}/lib/libykpers*.so.* $out/lib
cp -pdv ${pkgs.libyubikey}/lib/libyubikey*.so.* $out/lib
cp -pdv ${pkgs.openssl}/lib/libssl*.so.* $out/lib
cp -pdv ${pkgs.openssl}/lib/libcrypto*.so.* $out/lib
cc -O3 -I${pkgs.openssl}/include -L${pkgs.openssl}/lib ${./pbkdf2-sha512.c} -o pbkdf2-sha512 -lcrypto
strip -s pbkdf2-sha512
copy_bin_and_libs pbkdf2-sha512
mkdir -p $out/etc/ssl
cp -pdv ${pkgs.openssl}/etc/ssl/openssl.cnf $out/etc/ssl

View File

@ -39,42 +39,53 @@ let
mkdir -p $out/bin $out/lib
ln -s $out/bin $out/sbin
# Copy what we need from Glibc.
# Copy ld manually since it isn't detected correctly
cp -pv ${pkgs.glibc}/lib/ld*.so.? $out/lib
cp -pv ${pkgs.glibc}/lib/libc.so.* $out/lib
cp -pv ${pkgs.glibc}/lib/libm.so.* $out/lib
cp -pv ${pkgs.glibc}/lib/libpthread.so.* $out/lib
cp -pv ${pkgs.glibc}/lib/librt.so.* $out/lib
cp -pv ${pkgs.glibc}/lib/libdl.so.* $out/lib
cp -pv ${pkgs.gcc.cc}/lib*/libgcc_s.so.* $out/lib
copy_bin_and_libs () {
[ -f "$out/bin/$(basename $1)" ] && return 0
cp -pdv $1 $out/bin
LDD="$(ldd $1)"
[ "$?" -eq "1" ] && return 0
LIBS="$(echo "$LDD" | awk '{print $3}' | sed '/^$/d')"
for LIB in $LIBS; do
[ ! -f "$out/lib/$(basename $LIB)" ] && cp -pdv $LIB $out/lib
while [ "$(readlink $LIB)" != "" ]; do
LINK="$(readlink $LIB)"
if [ "${LINK:0:1}" != "/" ]; then
LINK="$(dirname $LIB)/$LINK"
fi
LIB="$LINK"
[ ! -f "$out/lib/$(basename $LIB)" ] && cp -pdv $LIB $out/lib
done
done
return 0
}
# Copy BusyBox.
cp -pvd ${pkgs.busybox}/bin/* ${pkgs.busybox}/sbin/* $out/bin/
for BIN in ${pkgs.busybox}/{s,}bin/*; do
copy_bin_and_libs $BIN
done
# Copy some utillinux stuff.
cp -vf --remove-destination ${pkgs.utillinux}/sbin/blkid $out/bin
cp -pdv ${pkgs.utillinux}/lib/libblkid*.so.* $out/lib
cp -pdv ${pkgs.utillinux}/lib/libuuid*.so.* $out/lib
copy_bin_and_libs ${pkgs.utillinux}/sbin/blkid
# Copy dmsetup and lvm.
cp -v ${pkgs.lvm2}/sbin/dmsetup $out/bin/dmsetup
cp -v ${pkgs.lvm2}/sbin/lvm $out/bin/lvm
cp -v ${pkgs.lvm2}/lib/libdevmapper.so.*.* $out/lib
cp -v ${pkgs.systemd}/lib/libsystemd.so.* $out/lib
copy_bin_and_libs ${pkgs.lvm2}/sbin/dmsetup
copy_bin_and_libs ${pkgs.lvm2}/sbin/lvm
# Add RAID mdadm tool.
cp -v ${pkgs.mdadm}/sbin/mdadm $out/bin/mdadm
copy_bin_and_libs ${pkgs.mdadm}/sbin/mdadm
# Copy udev.
cp -v ${udev}/lib/systemd/systemd-udevd ${udev}/bin/udevadm $out/bin
cp -v ${udev}/lib/udev/*_id $out/bin
cp -pdv ${udev}/lib/libudev.so.* $out/lib
cp -v ${pkgs.kmod}/lib/libkmod.so.* $out/lib
cp -v ${pkgs.acl}/lib/libacl.so.* $out/lib
cp -v ${pkgs.attr}/lib/libattr.so.* $out/lib
copy_bin_and_libs ${udev}/lib/systemd/systemd-udevd
copy_bin_and_libs ${udev}/bin/udevadm
for BIN in ${udev}/lib/udev/*_id; do
copy_bin_and_libs $BIN
done
# Copy modprobe.
cp -v ${pkgs.kmod}/bin/kmod $out/bin/
copy_bin_and_libs ${pkgs.kmod}/bin/kmod
ln -sf kmod $out/bin/modprobe
${config.boot.initrd.extraUtilsCommands}
@ -101,6 +112,7 @@ let
$out/bin/ash -c 'echo hello world' | grep "hello world"
export LD_LIBRARY_PATH=$out/lib
$out/bin/mount --help 2>&1 | grep "BusyBox"
$out/bin/blkid >/dev/null
$out/bin/udevadm --version
$out/bin/dmsetup --version 2>&1 | tee -a log | grep "version:"
LVM_SYSTEM_DIR=$out $out/bin/lvm version 2>&1 | tee -a log | grep "LVM"

View File

@ -17,13 +17,9 @@ in
boot.initrd.extraUtilsCommands = mkIf inInitrd
''
mkdir -p $out/bin
cp -v ${pkgs.btrfsProgs}/bin/btrfs $out/bin
copy_bin_and_libs ${pkgs.btrfsProgs}/bin/btrfs
ln -sv btrfs $out/bin/btrfsck
ln -sv btrfsck $out/bin/fsck.btrfs
# !!! Increases uncompressed initrd by 240k
cp -pv ${pkgs.zlib}/lib/libz.so* $out/lib
cp -pv ${pkgs.lzo}/lib/liblzo2.so* $out/lib
'';
boot.initrd.extraUtilsCommandsTest = mkIf inInitrd

View File

@ -18,7 +18,7 @@ in
boot.initrd.extraUtilsCommands = mkIf inInitrd
''
cp -v ${pkgs.cifs_utils}/sbin/mount.cifs $out/bin
copy_bin_and_libs ${pkgs.cifs_utils}/sbin/mount.cifs
'';
};

View File

@ -10,12 +10,11 @@
boot.initrd.extraUtilsCommands =
''
# Copy e2fsck and friends.
cp -v ${pkgs.e2fsprogs}/sbin/e2fsck $out/bin
cp -v ${pkgs.e2fsprogs}/sbin/tune2fs $out/bin
copy_bin_and_libs ${pkgs.e2fsprogs}/sbin/e2fsck
copy_bin_and_libs ${pkgs.e2fsprogs}/sbin/tune2fs
ln -sv e2fsck $out/bin/fsck.ext2
ln -sv e2fsck $out/bin/fsck.ext3
ln -sv e2fsck $out/bin/fsck.ext4
cp -pdv ${pkgs.e2fsprogs}/lib/lib*.so.* $out/lib
'';
};

View File

@ -13,9 +13,7 @@ in
boot.initrd.availableKernelModules = mkIf inInitrd [ "f2fs" ];
boot.initrd.extraUtilsCommands = mkIf inInitrd ''
mkdir -p $out/bin $out/lib
cp -v ${pkgs.f2fs-tools}/sbin/fsck.f2fs $out/bin
cp -pdv ${pkgs.f2fs-tools}/lib/lib*.so.* $out/lib
copy_bin_and_libs ${pkgs.f2fs-tools}/sbin/fsck.f2fs
'';
};
}

View File

@ -13,7 +13,7 @@ in
boot.initrd.kernelModules = mkIf inInitrd [ "jfs" ];
boot.initrd.extraUtilsCommands = mkIf inInitrd ''
cp -v ${pkgs.jfsutils}/sbin/fsck.jfs "$out/bin/"
copy_bin_and_libs ${pkgs.jfsutils}/sbin/fsck.jfs
'';
};
}

View File

@ -17,8 +17,7 @@ in
boot.initrd.extraUtilsCommands = mkIf inInitrd
''
cp -v ${pkgs.reiserfsprogs}/sbin/reiserfsck $out/bin
ln -sv reiserfsck $out/bin/fsck.reiserfs
copy_bin_and_libs ${pkgs.reiserfsprogs}/sbin/reiserfsck
'';
};

View File

@ -7,9 +7,8 @@
boot.initrd.kernelModules = [ "fuse" ];
boot.initrd.extraUtilsCommands = ''
cp -v ${pkgs.fuse}/lib/libfuse* $out/lib
cp -v ${pkgs.fuse}/sbin/mount.fuse $out/bin
cp -v ${pkgs.unionfs-fuse}/bin/unionfs $out/bin
copy_bin_and_libs ${pkgs.fuse}/sbin/mount.fuse
copy_bin_and_libs ${pkgs.unionfs-fuse}/bin/unionfs
substitute ${pkgs.unionfs-fuse}/sbin/mount.unionfs-fuse $out/bin/mount.unionfs-fuse \
--replace '${pkgs.bash}/bin/bash' /bin/sh \
--replace '${pkgs.fuse}/sbin' /bin \

View File

@ -17,8 +17,7 @@ in
boot.initrd.extraUtilsCommands = mkIf inInitrd
''
cp -v ${pkgs.dosfstools}/sbin/dosfsck $out/bin
ln -sv dosfsck $out/bin/fsck.vfat
copy_bin_and_libs ${pkgs.dosfstools}/sbin/dosfsck
'';
};

View File

@ -17,7 +17,7 @@ in
boot.initrd.extraUtilsCommands = mkIf inInitrd
''
cp -v ${pkgs.xfsprogs}/sbin/fsck.xfs $out/bin
copy_bin_and_libs ${pkgs.xfsprogs}/sbin/fsck.xfs
'';
# Trick just to set 'sh' after the extraUtils nuke-refs.

View File

@ -203,11 +203,14 @@ in
kernelModules = [ "spl" "zfs" ];
extraUtilsCommands =
''
cp -v ${zfsUserPkg}/sbin/zfs $out/bin
cp -v ${zfsUserPkg}/sbin/zdb $out/bin
cp -v ${zfsUserPkg}/sbin/zpool $out/bin
cp -pdv ${zfsUserPkg}/lib/lib*.so* $out/lib
cp -pdv ${pkgs.zlib}/lib/lib*.so* $out/lib
copy_bin_and_libs ${zfsUserPkg}/sbin/zfs
copy_bin_and_libs ${zfsUserPkg}/sbin/zdb
copy_bin_and_libs ${zfsUserPkg}/sbin/zpool
'';
extraUtilsCommandsTest = mkIf inInitrd
''
$out/bin/zfs --help >/dev/null 2>&1
$out/bin/zpool --help >/dev/null 2>&1
'';
postDeviceCommands = concatStringsSep "\n" ([''
ZFS_FORCE="${optionalString cfgZfs.forceImportRoot "-f"}"

View File

@ -165,7 +165,7 @@ in
boot.initrd.extraUtilsCommands =
''
# We need swapon in the initrd.
cp --remove-destination ${pkgs.utillinux}/sbin/swapon $out/bin
copy_bin_and_libs ${pkgs.utillinux}/sbin/swapon
'';
# Don't put old configurations in the GRUB menu. The user has no

View File

@ -346,7 +346,7 @@ in
boot.initrd.extraUtilsCommands =
''
# We need mke2fs in the initrd.
cp -vf --remove-destination ${pkgs.e2fsprogs}/sbin/mke2fs $out/bin
copy_bin_and_libs ${pkgs.e2fsprogs}/sbin/mke2fs
'';
boot.initrd.postDeviceCommands =

View File

@ -39,9 +39,8 @@ import ./make-test.nix ({ pkgs, ... }: with pkgs.lib; let
];
boot.initrd.extraUtilsCommands = ''
cp -av -t "$out/bin/" \
"${pkgs.linuxPackages.virtualboxGuestAdditions}/sbin/mount.vboxsf" \
"${pkgs.utillinux}/bin/unshare"
copy_bin_and_libs "${pkgs.linuxPackages.virtualboxGuestAdditions}/sbin/mount.vboxsf"
copy_bin_and_libs "${pkgs.utillinux}/bin/unshare"
${(attrs.extraUtilsCommands or (const "")) pkgs}
'';