Files
nix-packaging/threema-desktop.nix

118 lines
2.5 KiB
Nix

{
lib,
stdenv,
fetchFromGitHub,
rustPlatform,
nodejs,
python3,
cargo,
rustc,
binaryen,
pkg-config,
openssl,
wasm-bindgen-cli,
protobuf,
lld,
typescript,
}:
stdenv.mkDerivation rec {
pname = "threema-desktop";
version = "2.0-beta56";
src = fetchFromGitHub {
owner = "threema-ch";
repo = "threema-desktop";
rev = "v${version}";
hash = "sha256-wMIQ7piFPOBp0IleSnDSrZjaqXNBDyeELjx+938pmVk=";
};
cargoDeps = rustPlatform.fetchCargoVendor {
inherit src;
sourceRoot = "${src.name}/libs/libthreema";
hash = "sha256-SQ33LcCYlJ3W69TmpH1AkOKaREZ0p3KotJPuKZtc6yI=";
};
nativeBuildInputs = [
nodejs
python3
cargo
rustc
wasm-bindgen-cli
binaryen
pkg-config
protobuf
rustPlatform.bindgenHook
lld
typescript
];
buildInputs = [
openssl
];
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/
# 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; {
description = "Threema App for Desktop (Windows/macOS/Linux)";
longDescription = "A standalone Threema client for the desktop with end-to-end encryption";
homepage = "https://threema.ch/";
license = licenses.agpl3Plus;
maintainers = [ ];
platforms = platforms.linux;
};
}