depot/third_party/nixpkgs/pkgs/build-support/fetchfirefoxaddon/default.nix
Default email 22017988c6 Project import generated by Copybara.
GitOrigin-RevId: c777cdf5c564015d5f63b09cc93bef4178b19b01
2022-04-27 11:35:20 +02:00

44 lines
986 B
Nix

{stdenv, unzip, jq, zip, fetchurl,writeScript, ...}:
{
name
, url ? null
, md5 ? ""
, 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 md5 sha1 sha256 sha512 hash;
};
in
stdenv.mkDerivation {
inherit name;
passthru = {
inherit extid;
};
builder = writeScript "xpibuilder" ''
source $stdenv/setup
header "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" *
rm -r "$out/$UUID"
'';
nativeBuildInputs = [ unzip zip jq ];
}