buildFHSEnv: cleanup

This commit is contained in:
Atemu 2023-07-01 06:23:45 +02:00
parent 4bc72cae10
commit 167264179b

View file

@ -36,7 +36,7 @@ let
inherit (stdenv) is64bit; inherit (stdenv) is64bit;
# use of glibc_multi is only supported on x86_64-linux # use of glibc_multi is only supported on x86_64-linux
isMultiBuild = multiPkgs != null && stdenv.isx86_64 && stdenv.isLinux; isMultiBuild = stdenv.system == "x86_64-linux";
isTargetBuild = !isMultiBuild; isTargetBuild = !isMultiBuild;
# list of packages (usually programs) which are only be installed for the # list of packages (usually programs) which are only be installed for the
@ -51,21 +51,34 @@ let
# these match the host's architecture, glibc_multi is used for multilib # these match the host's architecture, glibc_multi is used for multilib
# builds. glibcLocales must be before glibc or glibc_multi as otherwiese # builds. glibcLocales must be before glibc or glibc_multi as otherwiese
# the wrong LOCALE_ARCHIVE will be used where only C.UTF-8 is available. # the wrong LOCALE_ARCHIVE will be used where only C.UTF-8 is available.
basePkgs = with pkgs; basePkgs = with pkgs; [
[ glibcLocales glibcLocales
(if isMultiBuild then glibc_multi else glibc) (if isMultiBuild then glibc_multi else glibc)
(toString gcc.cc.lib) bashInteractiveFHS coreutils less shadow su (toString gcc.cc.lib)
gawk diffutils findutils gnused gnugrep bashInteractiveFHS
gnutar gzip bzip2 xz coreutils
]; less
baseMultiPkgs = with pkgsi686Linux; shadow
[ (toString gcc.cc.lib) su
]; gawk
diffutils
findutils
gnused
gnugrep
gnutar
gzip
bzip2
xz
];
baseMultiPkgs = with pkgsi686Linux; [
(toString gcc.cc.lib)
];
ldconfig = writeShellScriptBin "ldconfig" '' ldconfig = writeShellScriptBin "ldconfig" ''
# due to a glibc bug, 64-bit ldconfig complains about patchelf'd 32-bit libraries, so we're using 32-bit ldconfig # due to a glibc bug, 64-bit ldconfig complains about patchelf'd 32-bit libraries, so we're using 32-bit ldconfig
exec ${if stdenv.isx86_64 && stdenv.isLinux then pkgsi686Linux.glibc.bin else pkgs.glibc.bin}/bin/ldconfig -f /etc/ld.so.conf -C /etc/ld.so.cache "$@" exec ${if stdenv.system == "x86_64-linux" then pkgsi686Linux.glibc.bin else pkgs.glibc.bin}/bin/ldconfig -f /etc/ld.so.conf -C /etc/ld.so.cache "$@"
''; '';
etcProfile = writeText "profile" '' etcProfile = writeText "profile" ''
export PS1='${name}-chrootenv:\u@\h:\w\$ ' export PS1='${name}-chrootenv:\u@\h:\w\$ '
export LOCALE_ARCHIVE='/usr/lib/locale/locale-archive' export LOCALE_ARCHIVE='/usr/lib/locale/locale-archive'
@ -104,7 +117,7 @@ let
# Compose /etc for the chroot environment # Compose /etc for the chroot environment
etcPkg = runCommandLocal "${name}-chrootenv-etc" { } '' etcPkg = runCommandLocal "${name}-chrootenv-etc" { } ''
mkdir -p $out/etc mkdir -p $out/etc
cd $out/etc pushd $out/etc
# environment variables # environment variables
ln -s ${etcProfile} profile ln -s ${etcProfile} profile
@ -172,13 +185,18 @@ let
ln -s lib64 lib ln -s lib64 lib
# copy glibc stuff # copy glibc stuff
cp -rsHf ${staticUsrProfileTarget}/lib/32/* lib32/ && chmod u+w -R lib32/ cp -rsHf ${staticUsrProfileTarget}/lib/32/* lib32/
chmod u+w -R lib32/
# copy content of multiPaths (32bit libs) # copy content of multiPaths (32bit libs)
[ -d ${staticUsrProfileMulti}/lib ] && cp -rsHf ${staticUsrProfileMulti}/lib/* lib32/ && chmod u+w -R lib32/ if [ -d ${staticUsrProfileMulti}/lib ]; then
cp -rsHf ${staticUsrProfileMulti}/lib/* lib32/
chmod u+w -R lib32/
fi
# copy content of targetPaths (64bit libs) # copy content of targetPaths (64bit libs)
cp -rsHf ${staticUsrProfileTarget}/lib/* lib64/ && chmod u+w -R lib64/ cp -rsHf ${staticUsrProfileTarget}/lib/* lib64/
chmod u+w -R lib64/
# symlink 32-bit ld-linux.so # symlink 32-bit ld-linux.so
ln -Ls ${staticUsrProfileTarget}/lib/32/ld-linux.so.2 lib/ ln -Ls ${staticUsrProfileTarget}/lib/32/ld-linux.so.2 lib/
@ -191,13 +209,15 @@ let
# the target profile is the actual profile that will be used for the chroot # the target profile is the actual profile that will be used for the chroot
setupTargetProfile = '' setupTargetProfile = ''
mkdir -m0755 usr mkdir -m0755 usr
cd usr pushd usr
${setupLibDirs} ${setupLibDirs}
${lib.optionalString isMultiBuild ''
'' + lib.optionalString isMultiBuild ''
if [ -d "${staticUsrProfileMulti}/share" ]; then if [ -d "${staticUsrProfileMulti}/share" ]; then
cp -rLf ${staticUsrProfileMulti}/share share cp -rLf ${staticUsrProfileMulti}/share share
fi fi
''} '' + ''
if [ -d "${staticUsrProfileTarget}/share" ]; then if [ -d "${staticUsrProfileTarget}/share" ]; then
if [ -d share ]; then if [ -d share ]; then
chmod -R 755 share chmod -R 755 share
@ -223,18 +243,19 @@ let
ln -s "$i" ln -s "$i"
fi fi
done done
popd
''; '';
in runCommandLocal "${name}-fhs" { in runCommandLocal "${name}-fhs" {
passthru = { passthru = {
inherit args multiPaths targetPaths; inherit args multiPaths targetPaths ldconfig;
}; };
} '' } ''
mkdir -p $out mkdir -p $out
cd $out pushd $out
${setupTargetProfile} ${setupTargetProfile}
cd $out
${extraBuildCommands} ${extraBuildCommands}
cd $out
${lib.optionalString isMultiBuild extraBuildCommandsMulti} ${lib.optionalString isMultiBuild extraBuildCommandsMulti}
'' ''