squirreldisk: use cargo-tauri.hook, build frontend in main derivation

This commit is contained in:
TomaSajt
2025-05-23 03:23:17 +02:00
parent c27e6d3b10
commit 4cc6bdd737
2 changed files with 31 additions and 96 deletions
-40
View File
@@ -1,40 +0,0 @@
{
"name": "squirreldisk-tauri",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"tauri": "tauri"
},
"dependencies": {
"@tauri-apps/api": "^1.2.0",
"d3": "^7.8.2",
"mongoid-js": "^1.3.0",
"pretty-bytes": "^6.0.0",
"react": "^18.2.0",
"react-beautiful-dnd": "^13.1.1",
"react-dom": "^18.2.0",
"react-router-dom": "^6.8.0",
"shade-blend-color": "^1.0.0",
"uuid": "^9.0.0",
"vscode-icons-js": "^11.6.1"
},
"devDependencies": {
"@tauri-apps/cli": "^1.2.2",
"@types/d3": "^7.4.0",
"@types/node": "^18.7.10",
"@types/react": "^18.0.15",
"@types/react-beautiful-dnd": "^13.1.3",
"@types/react-dom": "^18.0.6",
"@types/uuid": "^9.0.0",
"@vitejs/plugin-react": "^3.0.0",
"autoprefixer": "^10.4.13",
"postcss": "^8.4.21",
"tailwindcss": "^3.2.4",
"typescript": "^4.6.4",
"vite": "^4.0.0"
}
}
+31 -56
View File
@@ -9,14 +9,16 @@
wrapGAppsHook3,
parallel-disk-usage,
fetchFromGitHub,
buildNpmPackage,
fetchNpmDeps,
npmHooks,
nodejs,
rustPlatform,
cargo-tauri_1,
lib,
stdenv,
copyDesktopItems,
makeDesktopItem,
}:
let
rustPlatform.buildRustPackage rec {
pname = "squirreldisk";
version = "0.3.4";
@@ -26,51 +28,39 @@ let
rev = "v${version}";
hash = "sha256-As2nvc68knjeLPuX0QLBoybj8vuvkpS5Vr+7U7E5CjA=";
};
frontend-build = buildNpmPackage {
inherit version src;
pname = "squirreldisk-ui";
npmDepsHash = "sha256-Japcn0KYP7aYIDK8+Ns+mrnbbAb0fLWXHIV2+yltI6I=";
packageJSON = ./package.json;
postBuild = ''
cp -r dist/ $out
'';
distPhase = "true";
dontInstall = true;
patches = [
# Update field names to work with pdu versions >=0.10.0
# https://github.com/adileo/squirreldisk/pull/47
./update-pdu-json-format.patch
];
};
in
rustPlatform.buildRustPackage rec {
inherit version src pname;
sourceRoot = "${src.name}/src-tauri";
cargoRoot = "src-tauri";
buildAndTestSubdir = "src-tauri";
useFetchCargoVendor = true;
cargoHash = "sha256-dFTdbMX355klZ2wY160bYcgMiOiOGplEU7/e6Btv5JI=";
# copy the frontend static resources to final build directory
# Also modify tauri.conf.json so that it expects the resources at the new location
npmDeps = fetchNpmDeps {
name = "squirreldisk-${version}-npm-deps";
inherit src;
hash = "sha256-Japcn0KYP7aYIDK8+Ns+mrnbbAb0fLWXHIV2+yltI6I=";
};
patches = [
# Update field names to work with pdu versions >=0.10.0
# https://github.com/adileo/squirreldisk/pull/47
./update-pdu-json-format.patch
];
postPatch = ''
mkdir -p frontend-build
cp -r ${frontend-build}/* frontend-build
substituteInPlace tauri.conf.json --replace-fail '"distDir": "../dist"' '"distDir": "./frontend-build"'
# Copy pdu binary from nixpkgs, since the default packaged binary has issues.
cp ${parallel-disk-usage}/bin/pdu bin/pdu-${stdenv.hostPlatform.config}
# Use pdu binary from nixpkgs instead of the vendored prebuilt binary
rm src-tauri/bin/pdu-*
cp ${parallel-disk-usage}/bin/pdu src-tauri/bin/pdu-${stdenv.hostPlatform.rust.rustcTarget}
'';
nativeBuildInputs = [
pkg-config
wrapGAppsHook3
copyDesktopItems
npmHooks.npmConfigHook
nodejs
cargo-tauri_1.hook
];
buildInputs = [
dbus
openssl
@@ -83,35 +73,20 @@ rustPlatform.buildRustPackage rec {
# Disable checkPhase, since the project doesn't contain tests
doCheck = false;
postInstall = ''
mv $out/bin/squirreldisk-tauri $out/bin/squirreldisk
install -DT icons/256x256.png $out/share/icons/hicolor/256x256/apps/squirrel-disk.png
install -DT icons/128x128@2x.png $out/share/icons/hicolor/128x128@2/apps/squirrel-disk.png
install -DT icons/128x128.png $out/share/icons/hicolor/128x128/apps/squirrel-disk.png
install -DT icons/32x32.png $out/share/icons/hicolor/32x32/apps/squirrel-disk.png
'';
# We'll wrap the main binary manually
dontWrapGApps = true;
# WEBKIT_DISABLE_COMPOSITING_MODE essential in NVIDIA + compositor https://github.com/NixOS/nixpkgs/issues/212064#issuecomment-1400202079
postFixup = ''
wrapProgram "$out/bin/squirreldisk" \
wrapGApp "$out/bin/squirrel-disk" \
--set WEBKIT_DISABLE_COMPOSITING_MODE 1
'';
desktopItems = [
(makeDesktopItem {
name = "SquirrelDisk";
exec = "squirreldisk";
icon = "squirrel-disk";
desktopName = "SquirrelDisk";
comment = meta.description;
})
];
meta = with lib; {
description = "Cross-platform disk usage analysis tool";
homepage = "https://www.squirreldisk.com/";
license = licenses.agpl3Only;
maintainers = with maintainers; [ peret ];
mainProgram = "squirreldisk";
mainProgram = "squirrel-disk";
};
}