Merge pull request #223363 from wegank/prl-tools-refactor
prl-tools: refactor
This commit is contained in:
commit
bfb509a5f8
1 changed files with 123 additions and 104 deletions
|
@ -1,28 +1,39 @@
|
||||||
{ stdenv
|
{ lib
|
||||||
, lib
|
, stdenv
|
||||||
|
, fetchurl
|
||||||
|
, autoPatchelfHook
|
||||||
|
, bbe
|
||||||
, makeWrapper
|
, makeWrapper
|
||||||
, p7zip
|
, p7zip
|
||||||
, gawk
|
|
||||||
, util-linux
|
|
||||||
, xorg
|
|
||||||
, glib
|
|
||||||
, dbus-glib
|
|
||||||
, zlib
|
|
||||||
, bbe
|
|
||||||
, bash
|
|
||||||
, timetrap
|
|
||||||
, netcat
|
|
||||||
, cups
|
|
||||||
, kernel ? null
|
|
||||||
, libsOnly ? false
|
|
||||||
, fetchurl
|
|
||||||
, undmg
|
|
||||||
, perl
|
, perl
|
||||||
, autoPatchelfHook
|
, undmg
|
||||||
|
, dbus-glib
|
||||||
|
, glib
|
||||||
|
, xorg
|
||||||
|
, zlib
|
||||||
|
, kernel
|
||||||
|
, bash
|
||||||
|
, cups
|
||||||
|
, gawk
|
||||||
|
, netcat
|
||||||
|
, timetrap
|
||||||
|
, util-linux
|
||||||
}:
|
}:
|
||||||
|
|
||||||
assert (!libsOnly) -> kernel != null;
|
let
|
||||||
|
kernelVersion = kernel.modDirVersion;
|
||||||
|
kernelDir = "${kernel.dev}/lib/modules/${kernelVersion}";
|
||||||
|
|
||||||
|
libPath = lib.concatStringsSep ":" [ "${glib.out}/lib" "${xorg.libXrandr}/lib" ];
|
||||||
|
scriptPath = lib.concatStringsSep ":" [
|
||||||
|
"${bash}/bin"
|
||||||
|
"${cups}/sbin"
|
||||||
|
"${gawk}/bin"
|
||||||
|
"${netcat}/bin"
|
||||||
|
"${timetrap}/bin"
|
||||||
|
"${util-linux}/bin"
|
||||||
|
];
|
||||||
|
in
|
||||||
stdenv.mkDerivation rec {
|
stdenv.mkDerivation rec {
|
||||||
version = "18.2.0-53488";
|
version = "18.2.0-53488";
|
||||||
pname = "prl-tools";
|
pname = "prl-tools";
|
||||||
|
@ -36,124 +47,132 @@ stdenv.mkDerivation rec {
|
||||||
|
|
||||||
hardeningDisable = [ "pic" "format" ];
|
hardeningDisable = [ "pic" "format" ];
|
||||||
|
|
||||||
nativeBuildInputs = [ p7zip undmg perl bbe autoPatchelfHook ]
|
nativeBuildInputs = [
|
||||||
++ lib.optionals (!libsOnly) [ makeWrapper ] ++ kernel.moduleBuildDependencies;
|
autoPatchelfHook
|
||||||
|
bbe
|
||||||
|
makeWrapper
|
||||||
|
p7zip
|
||||||
|
perl
|
||||||
|
undmg
|
||||||
|
] ++ kernel.moduleBuildDependencies;
|
||||||
|
|
||||||
buildInputs = with xorg; [ libXrandr libXext libX11 libXcomposite libXinerama ]
|
buildInputs = [
|
||||||
++ lib.optionals (!libsOnly) [ libXi glib dbus-glib zlib ];
|
dbus-glib
|
||||||
|
glib
|
||||||
|
xorg.libX11
|
||||||
|
xorg.libXcomposite
|
||||||
|
xorg.libXext
|
||||||
|
xorg.libXrandr
|
||||||
|
xorg.libXi
|
||||||
|
xorg.libXinerama
|
||||||
|
zlib
|
||||||
|
];
|
||||||
|
|
||||||
runtimeDependencies = [ glib xorg.libXrandr ];
|
runtimeDependencies = [
|
||||||
|
glib
|
||||||
inherit libsOnly;
|
xorg.libXrandr
|
||||||
|
];
|
||||||
|
|
||||||
unpackPhase = ''
|
unpackPhase = ''
|
||||||
|
runHook preUnpack
|
||||||
|
|
||||||
undmg $src
|
undmg $src
|
||||||
export sourceRoot=prl-tools-build
|
export sourceRoot=prl-tools-build
|
||||||
7z x "Parallels Desktop.app/Contents/Resources/Tools/prl-tools-lin${lib.optionalString stdenv.isAarch64 "-arm"}.iso" -o$sourceRoot
|
7z x "Parallels Desktop.app/Contents/Resources/Tools/prl-tools-lin${lib.optionalString stdenv.isAarch64 "-arm"}.iso" -o$sourceRoot
|
||||||
if test -z "$libsOnly"; then
|
( cd $sourceRoot/kmods; tar -xaf prl_mod.tar.gz )
|
||||||
( cd $sourceRoot/kmods; tar -xaf prl_mod.tar.gz )
|
|
||||||
fi
|
runHook postUnpack
|
||||||
'';
|
'';
|
||||||
|
|
||||||
kernelVersion = lib.optionalString (!libsOnly) kernel.modDirVersion;
|
env.NIX_CFLAGS_COMPILE = lib.optionalString (lib.versionAtLeast kernelVersion "6.3") "-Wno-incompatible-pointer-types";
|
||||||
kernelDir = lib.optionalString (!libsOnly) "${kernel.dev}/lib/modules/${kernelVersion}";
|
|
||||||
|
|
||||||
libPath = lib.concatStringsSep ":" [ "${glib.out}/lib" "${xorg.libXrandr}/lib" ];
|
|
||||||
|
|
||||||
scriptPath = lib.concatStringsSep ":" (lib.optionals (!libsOnly) [
|
|
||||||
"${util-linux}/bin"
|
|
||||||
"${gawk}/bin"
|
|
||||||
"${bash}/bin"
|
|
||||||
"${timetrap}/bin"
|
|
||||||
"${netcat}/bin"
|
|
||||||
"${cups}/sbin"
|
|
||||||
]);
|
|
||||||
|
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
if test -z "$libsOnly"; then
|
runHook preBuild
|
||||||
( # kernel modules
|
|
||||||
cd kmods
|
( # kernel modules
|
||||||
make -f Makefile.kmods \
|
cd kmods
|
||||||
KSRC=$kernelDir/source \
|
make -f Makefile.kmods \
|
||||||
HEADERS_CHECK_DIR=$kernelDir/source \
|
KSRC=${kernelDir}/source \
|
||||||
KERNEL_DIR=$kernelDir/build \
|
HEADERS_CHECK_DIR=${kernelDir}/source \
|
||||||
SRC=$kernelDir/build \
|
KERNEL_DIR=${kernelDir}/build \
|
||||||
KVER=$kernelVersion
|
SRC=${kernelDir}/build \
|
||||||
)
|
KVER=${kernelVersion}
|
||||||
fi
|
)
|
||||||
|
|
||||||
|
runHook postBuild
|
||||||
'';
|
'';
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
if test -z "$libsOnly"; then
|
runHook preInstall
|
||||||
( # kernel modules
|
|
||||||
cd kmods
|
( # kernel modules
|
||||||
mkdir -p $out/lib/modules/${kernelVersion}/extra
|
cd kmods
|
||||||
cp prl_fs/SharedFolders/Guest/Linux/prl_fs/prl_fs.ko $out/lib/modules/${kernelVersion}/extra
|
mkdir -p $out/lib/modules/${kernelVersion}/extra
|
||||||
cp prl_fs_freeze/Snapshot/Guest/Linux/prl_freeze/prl_fs_freeze.ko $out/lib/modules/${kernelVersion}/extra
|
cp prl_fs/SharedFolders/Guest/Linux/prl_fs/prl_fs.ko $out/lib/modules/${kernelVersion}/extra
|
||||||
cp prl_tg/Toolgate/Guest/Linux/prl_tg/prl_tg.ko $out/lib/modules/${kernelVersion}/extra
|
cp prl_fs_freeze/Snapshot/Guest/Linux/prl_freeze/prl_fs_freeze.ko $out/lib/modules/${kernelVersion}/extra
|
||||||
${lib.optionalString stdenv.isAarch64
|
cp prl_tg/Toolgate/Guest/Linux/prl_tg/prl_tg.ko $out/lib/modules/${kernelVersion}/extra
|
||||||
"cp prl_notifier/Installation/lnx/prl_notifier/prl_notifier.ko $out/lib/modules/${kernelVersion}/extra"}
|
${lib.optionalString stdenv.isAarch64
|
||||||
)
|
"cp prl_notifier/Installation/lnx/prl_notifier/prl_notifier.ko $out/lib/modules/${kernelVersion}/extra"}
|
||||||
fi
|
)
|
||||||
|
|
||||||
( # tools
|
( # tools
|
||||||
cd tools/tools${if stdenv.isAarch64 then "-arm64" else if stdenv.isx86_64 then "64" else "32"}
|
cd tools/tools${if stdenv.isAarch64 then "-arm64" else if stdenv.isx86_64 then "64" else "32"}
|
||||||
mkdir -p $out/lib
|
mkdir -p $out/lib
|
||||||
|
|
||||||
if test -z "$libsOnly"; then
|
# prltoolsd contains hardcoded /bin/bash path
|
||||||
# prltoolsd contains hardcoded /bin/bash path
|
# we're lucky because it uses only -c command
|
||||||
# we're lucky because it uses only -c command
|
# => replace to /bin/sh
|
||||||
# => replace to /bin/sh
|
bbe -e "s:/bin/bash:/bin/sh\x00\x00:" -o bin/prltoolsd.tmp bin/prltoolsd
|
||||||
bbe -e "s:/bin/bash:/bin/sh\x00\x00:" -o bin/prltoolsd.tmp bin/prltoolsd
|
rm -f bin/prltoolsd
|
||||||
rm -f bin/prltoolsd
|
mv bin/prltoolsd.tmp bin/prltoolsd
|
||||||
mv bin/prltoolsd.tmp bin/prltoolsd
|
|
||||||
|
|
||||||
# install binaries
|
# install binaries
|
||||||
for i in bin/* sbin/prl_nettool sbin/prl_snapshot; do
|
for i in bin/* sbin/prl_nettool sbin/prl_snapshot; do
|
||||||
# also patch binaries to replace /usr/bin/XXX to XXX
|
# also patch binaries to replace /usr/bin/XXX to XXX
|
||||||
# here a two possible cases:
|
# here a two possible cases:
|
||||||
# 1. it is uses as null terminated string and should be truncated by null;
|
# 1. it is uses as null terminated string and should be truncated by null;
|
||||||
# 2. it is uses inside shell script and should be truncated by space.
|
# 2. it is uses inside shell script and should be truncated by space.
|
||||||
for p in bin/* sbin/prl_nettool sbin/prl_snapshot sbin/prlfsmountd; do
|
for p in bin/* sbin/prl_nettool sbin/prl_snapshot sbin/prlfsmountd; do
|
||||||
p=$(basename $p)
|
p=$(basename $p)
|
||||||
bbe -e "s:/usr/bin/$p\x00:./$p\x00\x00\x00\x00\x00\x00\x00\x00:" -o $i.tmp $i
|
bbe -e "s:/usr/bin/$p\x00:./$p\x00\x00\x00\x00\x00\x00\x00\x00:" -o $i.tmp $i
|
||||||
bbe -e "s:/usr/sbin/$p\x00:./$p\x00\x00\x00\x00\x00\x00\x00\x00 :" -o $i $i.tmp
|
bbe -e "s:/usr/sbin/$p\x00:./$p\x00\x00\x00\x00\x00\x00\x00\x00 :" -o $i $i.tmp
|
||||||
bbe -e "s:/usr/bin/$p:$p :" -o $i.tmp $i
|
bbe -e "s:/usr/bin/$p:$p :" -o $i.tmp $i
|
||||||
bbe -e "s:/usr/sbin/$p:$p :" -o $i $i.tmp
|
bbe -e "s:/usr/sbin/$p:$p :" -o $i $i.tmp
|
||||||
done
|
|
||||||
|
|
||||||
install -Dm755 $i $out/$i
|
|
||||||
done
|
done
|
||||||
|
|
||||||
install -Dm755 ../../tools/prlfsmountd.sh $out/sbin/prlfsmountd
|
install -Dm755 $i $out/$i
|
||||||
for f in $out/bin/* $out/sbin/*; do
|
done
|
||||||
wrapProgram $f \
|
|
||||||
--prefix LD_LIBRARY_PATH ':' "$libPath" \
|
|
||||||
--prefix PATH ':' "$scriptPath"
|
|
||||||
done
|
|
||||||
|
|
||||||
for i in lib/libPrl*.0.0; do
|
install -Dm755 ../../tools/prlfsmountd.sh $out/sbin/prlfsmountd
|
||||||
cp $i $out/lib
|
for f in $out/bin/* $out/sbin/*; do
|
||||||
ln -s $out/$i $out/''${i%.0.0}
|
wrapProgram $f \
|
||||||
done
|
--prefix LD_LIBRARY_PATH ':' "${libPath}" \
|
||||||
|
--prefix PATH ':' "${scriptPath}"
|
||||||
|
done
|
||||||
|
|
||||||
mkdir -p $out/share/man/man8
|
for i in lib/libPrl*.0.0; do
|
||||||
install -Dm644 ../mount.prl_fs.8 $out/share/man/man8
|
cp $i $out/lib
|
||||||
|
ln -s $out/$i $out/''${i%.0.0}
|
||||||
|
done
|
||||||
|
|
||||||
substituteInPlace ../99prltoolsd-hibernate \
|
mkdir -p $out/share/man/man8
|
||||||
--replace "/bin/bash" "${bash}/bin/bash"
|
install -Dm644 ../mount.prl_fs.8 $out/share/man/man8
|
||||||
|
|
||||||
mkdir -p $out/etc/pm/sleep.d
|
substituteInPlace ../99prltoolsd-hibernate \
|
||||||
install -Dm644 ../99prltoolsd-hibernate $out/etc/pm/sleep.d
|
--replace "/bin/bash" "${bash}/bin/bash"
|
||||||
fi
|
|
||||||
|
mkdir -p $out/etc/pm/sleep.d
|
||||||
|
install -Dm644 ../99prltoolsd-hibernate $out/etc/pm/sleep.d
|
||||||
)
|
)
|
||||||
|
|
||||||
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
|
||||||
meta = with lib; {
|
meta = with lib; {
|
||||||
description = "Parallels Tools for Linux guests";
|
description = "Parallels Tools for Linux guests";
|
||||||
homepage = "https://parallels.com";
|
homepage = "https://parallels.com";
|
||||||
platforms = platforms.linux;
|
|
||||||
license = licenses.unfree;
|
license = licenses.unfree;
|
||||||
maintainers = with maintainers; [ catap wegank ];
|
maintainers = with maintainers; [ catap wegank ];
|
||||||
|
platforms = platforms.linux;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue