aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/pkgs/build-support/fetchfirefoxaddon/default.nix
blob: 3426743b2cf13da335dbd2fcaffe901704bfc8f1 (plain)
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
{stdenv, lib, coreutils, unzip, jq, zip, fetchurl,writeScript,  ...}:
{ name
, url
, md5 ? ""
, sha1 ? ""
, sha256 ? ""
, sha512 ? ""
}:
stdenv.mkDerivation rec {

  inherit name;
  extid = "${src.outputHash}@${name}";
  passthru = {
    exitd=extid;
  };

  builder = writeScript "xpibuilder" ''
    source $stdenv/setup

    header "firefox addon $name into $out"

    UUID="${extid}"
    mkdir -p "$out/$UUID"
    unzip -q ${src} -d "$out/$UUID"
    NEW_MANIFEST=$(jq '. + {"applications": { "gecko": { "id": "${extid}" }}, "browser_specific_settings":{"gecko":{"id": "${extid}"}}}' "$out/$UUID/manifest.json")
    echo "$NEW_MANIFEST" > "$out/$UUID/manifest.json"
    cd "$out/$UUID"
    zip -r -q -FS "$out/$UUID.xpi" *
    rm -r "$out/$UUID"
  '';
  src = fetchurl {
    url = url;
    inherit md5 sha1 sha256 sha512;
  };
  nativeBuildInputs = [ coreutils unzip zip jq  ];
}