webtorrent_desktop: build from source and use packaged electron

new source version 0.21.0 -> 0.24.0
This commit is contained in:
Herwig Hochleitner 2022-12-13 18:51:30 +01:00
parent 3cb5bc287d
commit df1ff1b253

View file

@ -1,76 +1,50 @@
## FIXME: see ../../../servers/code-server/ for a proper yarn packaging { lib, stdenv, electron_22, buildNpmPackage, fetchFromGitHub }:
## - export ELECTRON_SKIP_BINARY_DOWNLOAD=1
## - jq "del(.scripts.preinstall)" node_modules/shellcheck/package.json | sponge node_modules/shellcheck/package.json buildNpmPackage {
{
lib, stdenv, buildFHSEnv, runCommand, writeScript, fetchurl, fetchzip
}:
let
pname = "webtorrent-desktop"; pname = "webtorrent-desktop";
version = "0.21.0"; version = "0.25-pre";
in src = fetchFromGitHub {
runCommand "${pname}-${version}" rec { owner = "webtorrent";
inherit (stdenv) shell; repo = "webtorrent-desktop";
inherit pname version; rev = "fce078defefd575cb35a5c79d3d9f96affc8a08f";
src = sha256 = "sha256-gXFiG36qqR0QHTqhaxgQKDO0UCHkJLnVwUTQB/Nct/c=";
if stdenv.hostPlatform.system == "x86_64-linux" then };
fetchzip { npmDepsHash = "sha256-pEuvstrZ9oMdJ/iU6XwEQ1BYOyQp/ce6sYBTrMCjGMc=";
url = "https://github.com/webtorrent/webtorrent-desktop/releases/download/v${version}/WebTorrent-v${version}-linux.zip"; makeCacheWritable = true;
sha256 = "13gd8isq2l10kibsc1bsc15dbgpnwa7nw4cwcamycgx6pfz9a852"; npmRebuildFlags = [ "--ignore-scripts" ];
} installPhase = ''
else ## Rebuild node_modules for production
throw "Webtorrent is not currently supported on ${stdenv.hostPlatform.system}"; ## after babel compile has finished
rm -r node_modules
export NODE_ENV=production
npm ci --ignore-scripts
fhs = buildFHSEnv rec { ## delete unused files
name = "fhsEnterWebTorrent"; rm -r test
runScript = "${src}/WebTorrent";
## use the trampoline, if you need to shell into the fhsenv
# runScript = writeScript "trampoline" ''
# #!/bin/sh
# exec "$@"
# '';
targetPkgs = pkgs: with pkgs; with xorg; [
alsa-lib atk at-spi2-core at-spi2-atk cairo cups dbus expat
fontconfig freetype gdk-pixbuf glib gtk3 pango libuuid libX11
libXScrnSaver libXcomposite libXcursor libXdamage libXext
libXfixes libXi libXrandr libXrender libXtst libxcb nspr nss
stdenv.cc.cc udev
];
# extraBwrapArgs = [
# "--ro-bind /run/user/$(id -u)/pulse /run/user/$(id -u)/pulse"
# ];
};
desktopFile = fetchurl { ## delete config for build time cache
url = "https://raw.githubusercontent.com/webtorrent/webtorrent-desktop/v${version}/static/linux/share/applications/webtorrent-desktop.desktop"; npm config delete cache
sha256 = "1v16dqbxqds3cqg3xkzxsa5fyd8ssddvjhy9g3i3lz90n47916ca";
}; ## add script wrapper and desktop files; icons
icon256File = fetchurl { mkdir -p $out/lib $out/bin $out/share/applications
url = "https://raw.githubusercontent.com/webtorrent/webtorrent-desktop/v${version}/static/linux/share/icons/hicolor/256x256/apps/webtorrent-desktop.png"; cp -r . $out/lib/webtorrent-desktop
sha256 = "1dapxvvp7cx52zhyaby4bxm4rll9xc7x3wk8k0il4g3mc7zzn3yk"; cat > $out/bin/WebTorrent <<EOF
}; #! ${stdenv.shell}
icon48File = fetchurl { set -eu
url = "https://raw.githubusercontent.com/webtorrent/webtorrent-desktop/v${version}/static/linux/share/icons/hicolor/48x48/apps/webtorrent-desktop.png"; exec ${electron_22}/bin/electron --no-sandbox $out/lib/webtorrent-desktop "\$@"
sha256 = "00y96w9shbbrdbf6xcjlahqd08154kkrxmqraik7qshiwcqpw7p4"; EOF
}; chmod +x $out/bin/WebTorrent
cp -r static/linux/share/icons $out/share/
sed "s#/opt/webtorrent-desktop#$out/bin#" \
< static/linux/share/applications/webtorrent-desktop.desktop \
> $out/share/applications/webtorrent-desktop.desktop
'';
meta = with lib; { meta = with lib; {
description = "Streaming torrent app for Mac, Windows, and Linux"; description = "Streaming torrent app for Mac, Windows, and Linux";
homepage = "https://webtorrent.io/desktop"; homepage = "https://webtorrent.io/desktop";
license = licenses.mit; license = licenses.mit;
maintainers = [ maintainers.flokli maintainers.bendlas ]; maintainers = [ maintainers.flokli maintainers.bendlas ];
platforms = [
"x86_64-linux"
];
}; };
} '' }
mkdir -p $out/{bin,share/{applications,icons/hicolor/{48x48,256x256}/apps}}
cp $fhs/bin/fhsEnterWebTorrent $out/bin/WebTorrent
cp $icon48File $out/share/icons/hicolor/48x48/apps/webtorrent-desktop.png
cp $icon256File $out/share/icons/hicolor/256x256/apps/webtorrent-desktop.png
## Fix the desktop link
substitute $desktopFile $out/share/applications/webtorrent-desktop.desktop \
--replace /opt/webtorrent-desktop $out/libexec
''