diff --git a/threema-desktop.nix b/threema-desktop.nix index a252d9b..676ed3f 100644 --- a/threema-desktop.nix +++ b/threema-desktop.nix @@ -1,17 +1,22 @@ { lib, - buildNpmPackage, + stdenv, fetchFromGitHub, rustPlatform, + nodejs, + python3, + cargo, + rustc, binaryen, pkg-config, openssl, wasm-bindgen-cli, protobuf, lld, + typescript, }: -buildNpmPackage rec { +stdenv.mkDerivation rec { pname = "threema-desktop"; version = "2.0-beta56"; @@ -22,12 +27,6 @@ buildNpmPackage rec { 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 { inherit src; sourceRoot = "${src.name}/libs/libthreema"; @@ -35,12 +34,17 @@ buildNpmPackage rec { }; nativeBuildInputs = [ - rustPlatform.bindgenHook + nodejs + python3 + cargo + rustc wasm-bindgen-cli binaryen pkg-config protobuf + rustPlatform.bindgenHook lld + typescript ]; buildInputs = [ @@ -50,19 +54,56 @@ buildNpmPackage rec { postPatch = '' patchShebangs --build ./tools patchShebangs --build ./libs/libthreema/tools + + # Remove strict engine requirements from package.json to allow close versions 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 = '' runHook preBuild + + # Build libthreema WASM npm run libthreema:build + + # Package as binary npm run package binary consumer-live + runHook postBuild ''; installPhase = '' 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; {