94 lines
3 KiB
Nix
94 lines
3 KiB
Nix
{
|
|
lib,
|
|
craneLib,
|
|
pkg-config,
|
|
qt6,
|
|
writeShellScript,
|
|
runCommand,
|
|
}:
|
|
let
|
|
# nixpkgs splits Qt tools across packages: moc/rcc/qtpaths live in qtbase,
|
|
# qmltyperegistrar and qmlcachegen live in qtdeclarative. qt-build-utils
|
|
# finds tools via `qmake -query QT_INSTALL_LIBEXECS`, which only returns
|
|
# qtbase paths, so those two tools are invisible. Fix: combine them into a
|
|
# single symlink tree and point a qmake wrapper at it.
|
|
qtBuildTools = runCommand "qt6-build-tools" { } ''
|
|
mkdir -p $out/libexec $out/bin
|
|
for f in ${qt6.qtbase}/libexec/* ${qt6.qtbase}/bin/*; do
|
|
ln -sf "$f" "$out/$(echo "$f" | grep -o 'libexec\|bin')/$(basename "$f")"
|
|
done
|
|
for tool in qmltyperegistrar qmlcachegen; do
|
|
src="${qt6.qtdeclarative}/libexec/$tool"
|
|
[ -f "$src" ] && ln -sf "$src" "$out/libexec/$tool"
|
|
done
|
|
'';
|
|
qmakeWrapper = writeShellScript "qmake6" ''
|
|
if [ "$1" = "-query" ]; then
|
|
case "$2" in
|
|
QT_HOST_LIBEXECS|QT_HOST_LIBEXECS/get|QT_INSTALL_LIBEXECS|QT_INSTALL_LIBEXECS/get)
|
|
echo "${qtBuildTools}/libexec"; exit 0;;
|
|
QT_HOST_BINS|QT_HOST_BINS/get|QT_INSTALL_BINS|QT_INSTALL_BINS/get)
|
|
echo "${qtBuildTools}/bin"; exit 0;;
|
|
esac
|
|
fi
|
|
exec ${qt6.qtbase}/bin/qmake6 "$@"
|
|
'';
|
|
|
|
# Args shared between the deps-only build (cached on Cargo.lock changes only)
|
|
# and the final crate build. cxx-qt-build runs during the deps build too, so it
|
|
# needs the Qt env to find qmltyperegistrar/qmlcachegen.
|
|
commonArgs = {
|
|
pname = "nova-plugin";
|
|
version = "0.1.0";
|
|
src = craneLib.cleanCargoSource ../plugin;
|
|
strictDeps = true;
|
|
|
|
nativeBuildInputs = [
|
|
pkg-config
|
|
qt6.qtbase
|
|
qt6.qtdeclarative
|
|
];
|
|
buildInputs = [
|
|
qt6.qtbase
|
|
qt6.qtdeclarative
|
|
];
|
|
|
|
dontWrapQtApps = true;
|
|
|
|
# qt6.qtbase's setup hook overrides QMAKE after derivation attrs are set,
|
|
# so re-assert it in preBuild which runs after all setup hooks.
|
|
preBuild = ''
|
|
export QMAKE=${qmakeWrapper}
|
|
'';
|
|
};
|
|
|
|
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
|
in
|
|
craneLib.buildPackage (
|
|
commonArgs
|
|
// {
|
|
inherit cargoArtifacts;
|
|
|
|
# Crane's default cargo build doesn't set CARGO_BUILD_TARGET, so artifacts land
|
|
# in `target/release/` and cxx-qt files in `target/cxxqt/...` (no triple subdir,
|
|
# unlike nixpkgs rustPlatform). Use `find` to stay agnostic to either layout.
|
|
installPhaseCommand = ''
|
|
qml_dir="$out/lib/qt-6/qml/NovaStats"
|
|
mkdir -p "$qml_dir"
|
|
|
|
so=$(find target -name 'libnova_plugin.so' -path '*/release/*' | head -1)
|
|
install -m755 "$so" "$qml_dir/libNovaStats.so"
|
|
|
|
qmldir=$(find target -path '*/cxxqt/qml_modules/NovaStats/qmldir' | head -1)
|
|
install -m644 "$qmldir" "$qml_dir/"
|
|
|
|
qmltypes=$(find target -path '*/cxxqt/qml_modules/NovaStats/plugin.qmltypes' | head -1)
|
|
[ -n "$qmltypes" ] && install -m644 "$qmltypes" "$qml_dir/" || true
|
|
'';
|
|
|
|
meta = {
|
|
description = "In-process system stats QML plugin for nova-shell";
|
|
platforms = lib.platforms.linux;
|
|
};
|
|
}
|
|
)
|