prl-tools: refactor

This commit is contained in:
Weijia Wang 2023-03-27 13:47:01 +03:00
parent 03b6ad65f3
commit 76694fdeb3

View file

@ -1,28 +1,39 @@
{ stdenv
, lib
{ lib
, stdenv
, fetchurl
, autoPatchelfHook
, bbe
, makeWrapper
, p7zip
, gawk
, util-linux
, xorg
, glib
, dbus-glib
, zlib
, bbe
, bash
, timetrap
, netcat
, cups
, kernel ? null
, libsOnly ? false
, fetchurl
, undmg
, 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 {
version = "18.2.0-53488";
pname = "prl-tools";
@ -36,55 +47,64 @@ stdenv.mkDerivation rec {
hardeningDisable = [ "pic" "format" ];
nativeBuildInputs = [ p7zip undmg perl bbe autoPatchelfHook ]
++ lib.optionals (!libsOnly) [ makeWrapper ] ++ kernel.moduleBuildDependencies;
nativeBuildInputs = [
autoPatchelfHook
bbe
makeWrapper
p7zip
perl
undmg
] ++ kernel.moduleBuildDependencies;
buildInputs = with xorg; [ libXrandr libXext libX11 libXcomposite libXinerama ]
++ lib.optionals (!libsOnly) [ libXi glib dbus-glib zlib ];
buildInputs = [
dbus-glib
glib
xorg.libX11
xorg.libXcomposite
xorg.libXext
xorg.libXrandr
xorg.libXi
xorg.libXinerama
zlib
];
runtimeDependencies = [ glib xorg.libXrandr ];
inherit libsOnly;
runtimeDependencies = [
glib
xorg.libXrandr
];
unpackPhase = ''
runHook preUnpack
undmg $src
export sourceRoot=prl-tools-build
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 )
fi
runHook postUnpack
'';
kernelVersion = lib.optionalString (!libsOnly) kernel.modDirVersion;
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"
]);
env.NIX_CFLAGS_COMPILE = lib.optionalString (lib.versionAtLeast kernelVersion "6.3") "-Wno-incompatible-pointer-types";
buildPhase = ''
if test -z "$libsOnly"; then
runHook preBuild
( # kernel modules
cd kmods
make -f Makefile.kmods \
KSRC=$kernelDir/source \
HEADERS_CHECK_DIR=$kernelDir/source \
KERNEL_DIR=$kernelDir/build \
SRC=$kernelDir/build \
KVER=$kernelVersion
KSRC=${kernelDir}/source \
HEADERS_CHECK_DIR=${kernelDir}/source \
KERNEL_DIR=${kernelDir}/build \
SRC=${kernelDir}/build \
KVER=${kernelVersion}
)
fi
runHook postBuild
'';
installPhase = ''
if test -z "$libsOnly"; then
runHook preInstall
( # kernel modules
cd kmods
mkdir -p $out/lib/modules/${kernelVersion}/extra
@ -94,13 +114,11 @@ stdenv.mkDerivation rec {
${lib.optionalString stdenv.isAarch64
"cp prl_notifier/Installation/lnx/prl_notifier/prl_notifier.ko $out/lib/modules/${kernelVersion}/extra"}
)
fi
( # tools
cd tools/tools${if stdenv.isAarch64 then "-arm64" else if stdenv.isx86_64 then "64" else "32"}
mkdir -p $out/lib
if test -z "$libsOnly"; then
# prltoolsd contains hardcoded /bin/bash path
# we're lucky because it uses only -c command
# => replace to /bin/sh
@ -128,8 +146,8 @@ stdenv.mkDerivation rec {
install -Dm755 ../../tools/prlfsmountd.sh $out/sbin/prlfsmountd
for f in $out/bin/* $out/sbin/*; do
wrapProgram $f \
--prefix LD_LIBRARY_PATH ':' "$libPath" \
--prefix PATH ':' "$scriptPath"
--prefix LD_LIBRARY_PATH ':' "${libPath}" \
--prefix PATH ':' "${scriptPath}"
done
for i in lib/libPrl*.0.0; do
@ -145,15 +163,16 @@ stdenv.mkDerivation rec {
mkdir -p $out/etc/pm/sleep.d
install -Dm644 ../99prltoolsd-hibernate $out/etc/pm/sleep.d
fi
)
runHook postInstall
'';
meta = with lib; {
description = "Parallels Tools for Linux guests";
homepage = "https://parallels.com";
platforms = platforms.linux;
license = licenses.unfree;
maintainers = with maintainers; [ catap wegank ];
platforms = platforms.linux;
};
}