btrbk: add mainProgram
[NixPkgs.git] / pkgs / by-name / we / webtorrent_desktop / package.nix
blob9fd34a1eed1fcd07350c7600613107f83bcf245a
1 { lib, stdenv, electron, buildNpmPackage, fetchFromGitHub, fetchpatch }:
3 buildNpmPackage {
4   pname = "webtorrent-desktop";
5   version = "0.25-pre-ac7f16";
6   src = fetchFromGitHub {
7     owner = "webtorrent";
8     repo = "webtorrent-desktop";
9     rev = "ac7f16e71c96c5ad670bfcb8728df5af78ae21a1";
10     sha256 = "sha256-UEN5NhLVSQEO8rsiTW1hJPjNFL9KobW/Bho98FzKaf4=";
11   };
12   patches = [
13     # startup fix
14     (fetchpatch {
15       name = "2389.patch"; # https://github.com/webtorrent/webtorrent-desktop/pull/2389
16       url = "https://github.com/webtorrent/webtorrent-desktop/commit/407046d150ed7ff876a5e1978f68630e9c8f0074.patch";
17       hash = "sha256-hBJGLNNjcGRhYOFlLm/RL0po+70tEeJtR6Y/CfacPAI=";
18     })
19   ];
20   npmDepsHash = "sha256-otAes6GkqoAVvfeWhWgyY4IVZIZxw3WtkrVdEWIk1Lk=";
21   makeCacheWritable = true;
22   npmRebuildFlags = [ "--ignore-scripts" ];
23   installPhase = ''
24     ## Rebuild node_modules for production
25     ## after babel compile has finished
26     rm -r node_modules
27     export NODE_ENV=production
28     npm ci --ignore-scripts
30     ## delete unused files
31     rm -r test
33     ## delete config for build time cache
34     npm config delete cache
36     ## add script wrapper and desktop files; icons
37     mkdir -p $out/lib $out/bin $out/share/applications
38     cp -r . $out/lib/webtorrent-desktop
39     cat > $out/bin/WebTorrent <<EOF
40     #! ${stdenv.shell}
41     set -eu
42     exec ${electron}/bin/electron --no-sandbox $out/lib/webtorrent-desktop "\$@"
43     EOF
44     chmod +x $out/bin/WebTorrent
45     cp -r static/linux/share/icons $out/share/
46     sed "s#/opt/webtorrent-desktop#$out/bin#" \
47       < static/linux/share/applications/webtorrent-desktop.desktop \
48       > $out/share/applications/webtorrent-desktop.desktop
49   '';
51   meta = with lib; {
52     description = "Streaming torrent app for Mac, Windows, and Linux";
53     homepage = "https://webtorrent.io/desktop";
54     license = licenses.mit;
55     maintainers = [ maintainers.bendlas ];
56     mainProgram = "WebTorrent";
57   };