summaryrefslogtreecommitdiff
path: root/pkgs/build-support/fetchfirefoxaddon/default.nix
blob: de1375d767f1106efc5dbb255be794274674e75a (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
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
{
  stdenv,
  fetchurl,
  jq,
  strip-nondeterminism,
  unzip,
  writeScript,
  zip,
}:

{
  name,
  url ? null,
  sha1 ? "",
  sha256 ? "",
  sha512 ? "",
  fixedExtid ? null,
  hash ? "",
  src ? "",
}:

let
  extid = if fixedExtid == null then "nixos@${name}" else fixedExtid;
  source =
    if url == null then
      src
    else
      fetchurl {
        url = url;
        inherit
          sha1
          sha256
          sha512
          hash
          ;
      };
in
stdenv.mkDerivation {
  inherit name;

  passthru = {
    inherit extid;
  };

  builder = writeScript "xpibuilder" ''
    echo "firefox addon $name into $out"

    UUID="${extid}"
    mkdir -p "$out/$UUID"
    unzip -q ${source} -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" *
    strip-nondeterminism "$out/$UUID.xpi"
    rm -r "$out/$UUID"
  '';

  nativeBuildInputs = [
    jq
    strip-nondeterminism
    unzip
    zip
  ];
}