nix: build nova-plugin via crane to cache deps separately from crate src

This commit is contained in:
Damocles 2026-05-03 20:01:47 +02:00
parent 2a691aa66f
commit bf5cb913fc
4 changed files with 88 additions and 44 deletions

View file

@ -1,6 +1,6 @@
{
lib,
rustPlatform,
craneLib,
pkg-config,
qt6,
writeShellScript,
@ -33,47 +33,62 @@ let
fi
exec ${qt6.qtbase}/bin/qmake6 "$@"
'';
in
rustPlatform.buildRustPackage {
pname = "nova-plugin";
version = "0.1.0";
src = lib.cleanSource ../plugin;
cargoLock.lockFile = ../plugin/Cargo.lock;
nativeBuildInputs = [
pkg-config
qt6.qtbase
qt6.qtdeclarative
];
# 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;
buildInputs = [
qt6.qtbase
qt6.qtdeclarative
];
nativeBuildInputs = [
pkg-config
qt6.qtbase
qt6.qtdeclarative
];
buildInputs = [
qt6.qtbase
qt6.qtdeclarative
];
dontWrapQtApps = true;
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}
'';
installPhase = ''
runHook preInstall
qml_dir="$out/lib/qt-6/qml/NovaStats"
mkdir -p "$qml_dir"
install -m755 target/*/release/libnova_plugin.so "$qml_dir/libNovaStats.so"
install -m644 target/*/cxxqt/qml_modules/NovaStats/qmldir "$qml_dir/"
install -m644 target/*/cxxqt/qml_modules/NovaStats/plugin.qmltypes "$qml_dir/" 2>/dev/null || true
runHook postInstall
'';
meta = {
description = "In-process system stats QML plugin for nova-shell";
platforms = lib.platforms.linux;
# 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;
};
}
)