core/pkgs/build-support/fetchfirefoxaddon/default.nix

38 lines
1 KiB
Nix
Raw Normal View History

2024-05-13 21:24:10 +00:00
{ stdenv, fetchurl, jq, strip-nondeterminism, unzip, writeScript, zip }:
2024-05-02 00:46:19 +00:00
2024-05-13 21:24:10 +00:00
{ name, url ? null, sha1 ? "", sha256 ? "", sha512 ? "", fixedExtid ? null
, hash ? "", src ? "" }:
2024-05-02 00:46:19 +00:00
let
extid = if fixedExtid == null then "nixos@${name}" else fixedExtid;
2024-05-13 21:24:10 +00:00
source = if url == null then
src
else
fetchurl {
url = url;
inherit sha1 sha256 sha512 hash;
};
in stdenv.mkDerivation {
2024-05-02 00:46:19 +00:00
inherit name;
2024-05-13 21:24:10 +00:00
passthru = { inherit extid; };
2024-05-02 00:46:19 +00:00
builder = writeScript "xpibuilder" ''
source $stdenv/setup
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"
'';
2024-05-13 21:24:10 +00:00
nativeBuildInputs = [ jq strip-nondeterminism unzip zip ];
2024-05-02 00:46:19 +00:00
}