Use mkDerivation instead of npmbuild

This commit is contained in:
2025-10-28 15:23:02 +01:00
parent 8e59f537c3
commit a218c94f0a

View File

@@ -1,17 +1,22 @@
{ {
lib, lib,
buildNpmPackage, stdenv,
fetchFromGitHub, fetchFromGitHub,
rustPlatform, rustPlatform,
nodejs,
python3,
cargo,
rustc,
binaryen, binaryen,
pkg-config, pkg-config,
openssl, openssl,
wasm-bindgen-cli, wasm-bindgen-cli,
protobuf, protobuf,
lld, lld,
typescript,
}: }:
buildNpmPackage rec { stdenv.mkDerivation rec {
pname = "threema-desktop"; pname = "threema-desktop";
version = "2.0-beta56"; version = "2.0-beta56";
@@ -22,12 +27,6 @@ buildNpmPackage rec {
hash = "sha256-wMIQ7piFPOBp0IleSnDSrZjaqXNBDyeELjx+938pmVk="; hash = "sha256-wMIQ7piFPOBp0IleSnDSrZjaqXNBDyeELjx+938pmVk=";
}; };
forceGitDeps = true;
npmDepsHash = "sha256-9pyBbA+MARxWPZzyvjyKCuofgt+X3DrDCa81S6/S5qg="; # replace after first build
npmFlags = [ "--legacy-peer-deps" ];
makeCacheWritable = true;
cargoDeps = rustPlatform.fetchCargoVendor { cargoDeps = rustPlatform.fetchCargoVendor {
inherit src; inherit src;
sourceRoot = "${src.name}/libs/libthreema"; sourceRoot = "${src.name}/libs/libthreema";
@@ -35,12 +34,17 @@ buildNpmPackage rec {
}; };
nativeBuildInputs = [ nativeBuildInputs = [
rustPlatform.bindgenHook nodejs
python3
cargo
rustc
wasm-bindgen-cli wasm-bindgen-cli
binaryen binaryen
pkg-config pkg-config
protobuf protobuf
rustPlatform.bindgenHook
lld lld
typescript
]; ];
buildInputs = [ buildInputs = [
@@ -50,19 +54,56 @@ buildNpmPackage rec {
postPatch = '' postPatch = ''
patchShebangs --build ./tools patchShebangs --build ./tools
patchShebangs --build ./libs/libthreema/tools patchShebangs --build ./libs/libthreema/tools
# Remove strict engine requirements from package.json to allow close versions
sed -i '/"engines":/,/},/d' package.json sed -i '/"engines":/,/},/d' package.json
''; '';
preBuild = ''
# Set npm home to a writable location
export NPM_CONFIG_CACHE=$TMPDIR/npm-cache
export NPM_CONFIG_USERCONFIG=$TMPDIR/.npmrc
# Disable engine strict checking via environment variable
export NPM_CONFIG_ENGINE_STRICT=false
# Set up Cargo environment in writable locations
export CARGO_HOME=$TMPDIR/cargo
mkdir -p $CARGO_HOME
# Configure Cargo to work offline using the vendored dependencies
cat > $CARGO_HOME/config.toml << EOF
[source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "${cargoDeps}"
EOF
'';
buildPhase = '' buildPhase = ''
runHook preBuild runHook preBuild
# Build libthreema WASM
npm run libthreema:build npm run libthreema:build
# Package as binary
npm run package binary consumer-live npm run package binary consumer-live
runHook postBuild runHook postBuild
''; '';
installPhase = '' installPhase = ''
mkdir -p $out/opt/threema-desktop mkdir -p $out/opt/threema-desktop
cp -r build/out/* $out/opt/threema-desktop cp -r build/out/* $out/opt/threema-desktop/
# Create a wrapper script
mkdir -p $out/bin
cat > $out/bin/threema-desktop << EOF
#!/bin/sh
exec $out/opt/threema-desktop/Threema "\$@"
EOF
chmod +x $out/bin/threema-desktop
''; '';
meta = with lib; { meta = with lib; {