squirreldisk: use cargo-tauri.hook, add darwin support, refactor (#406914)

This commit is contained in:
Toma
2025-05-23 03:47:11 +02:00
committed by GitHub
2 changed files with 66 additions and 117 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"
}
}
+66 -77
View File
@@ -1,22 +1,28 @@
{
dbus,
openssl,
freetype,
libsoup_2_4,
gtk3,
webkitgtk_4_0,
pkg-config,
wrapGAppsHook3,
parallel-disk-usage,
fetchFromGitHub,
buildNpmPackage,
rustPlatform,
lib,
stdenv,
copyDesktopItems,
makeDesktopItem,
rustPlatform,
fetchFromGitHub,
fetchNpmDeps,
cargo-tauri_1,
makeBinaryWrapper,
nodejs,
npmHooks,
pkg-config,
wrapGAppsHook3,
dbus,
freetype,
gtk3,
libsoup_2_4,
openssl,
parallel-disk-usage,
webkitgtk_4_0,
}:
let
rustPlatform.buildRustPackage rec {
pname = "squirreldisk";
version = "0.3.4";
@@ -26,92 +32,75 @@ 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
];
buildInputs = [
nativeBuildInputs =
[
cargo-tauri_1.hook
npmHooks.npmConfigHook
nodejs
]
++ lib.optionals stdenv.hostPlatform.isLinux [
pkg-config
wrapGAppsHook3
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
makeBinaryWrapper
];
buildInputs = lib.optionals stdenv.hostPlatform.isLinux [
dbus
openssl
freetype
libsoup_2_4
gtk3
libsoup_2_4
openssl
webkitgtk_4_0
];
# 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" \
--set WEBKIT_DISABLE_COMPOSITING_MODE 1
'';
desktopItems = [
(makeDesktopItem {
name = "SquirrelDisk";
exec = "squirreldisk";
icon = "squirrel-disk";
desktopName = "SquirrelDisk";
comment = meta.description;
})
];
postFixup =
lib.optionalString stdenv.hostPlatform.isLinux ''
wrapGApp "$out/bin/squirrel-disk" \
--set WEBKIT_DISABLE_COMPOSITING_MODE 1
''
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
makeWrapper "$out/Applications/SquirrelDisk.app/Contents/MacOS/SquirrelDisk" "$out/bin/squirrel-disk"
'';
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";
};
}