about summary refs log tree commit diff
path: root/pkgs/by-name/vd/vdhcoapp/package.nix
blob: ad61515b9ecbabfaf3b45c3843f49b6d76135228 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{ lib
, fetchFromGitHub
, buildNpmPackage
, nodejs
, ffmpeg
, callPackage
, substituteAll
, makeWrapper
, toml2json
, jq
}:
buildNpmPackage rec {
  pname = "vdhcoapp";
  version = "2.0.19";

  src = fetchFromGitHub {
    owner = "aclap-dev";
    repo = "vdhcoapp";
    rev = "v${version}";
    hash = "sha256-8xeZvqpRq71aShVogiwlVD3gQoPGseNOmz5E3KbsZxU=";
  };

  sourceRoot = "${src.name}/app";
  npmDepsHash = "sha256-E032U2XZdyTER6ROkBosOTn7bweDXHl8voC3BQEz8Wg=";
  dontNpmBuild = true;

  nativeBuildInputs = [
    makeWrapper
    toml2json
    jq
  ];

  patches = [
    (substituteAll {
      src = ./ffmpeg-filepicker.patch;
      inherit ffmpeg;
      filepicker = lib.getExe (callPackage ./filepicker.nix {});
    })
  ];

  postPatch = ''
    # Cannot use patch, setting placeholder here
    substituteInPlace src/native-autoinstall.js \
      --replace process.execPath "\"${placeholder "out"}/bin/vdhcoapp\""
  '';

  preBuild = ''
    toml2json --pretty ../config.toml > src/config.json
  '';

  installPhase = ''
    runHook preInstall
    mkdir -p $out/opt/vdhcoapp
    cp -r . "$out/opt/vdhcoapp"

    makeWrapper ${nodejs}/bin/node $out/bin/vdhcoapp \
      --add-flags $out/opt/vdhcoapp/src/main.js

    generateManifest() {
      type=$1
      outputFolder=$2
      mkdir -p $outputFolder
      manifestName=$(jq -r '.meta.id' src/config.json).json
      jq '.store.'$type'.manifest * (.meta | with_entries(select (.key == "description")) * {"name": .id}) * {"path" : "${placeholder "out"}/bin/vdhcoapp"}' src/config.json > $outputFolder/$manifestName
    }

    generateManifest google $out/etc/opt/chrome/native-messaging-hosts
    generateManifest google $out/etc/chromium/native-messaging-hosts
    generateManifest mozilla $out/lib/mozilla/native-messaging-hosts
    generateManifest google $out/etc/opt/edge/native-messaging-hosts

    runHook postInstall
  '';

  meta = with lib; {
    description = "Companion application for the Video DownloadHelper browser add-on";
    homepage = "https://www.downloadhelper.net/";
    license = licenses.gpl2;
    platforms = lib.platforms.linux;
    maintainers = with maintainers; [ hannesgith ];
    mainProgram = "vdhcoapp";
  };
}