2023-07-17 03:28:13 +00:00
|
|
|
{ stdenv
|
2023-07-17 05:25:12 +00:00
|
|
|
, callPackage
|
2023-07-17 22:19:29 +00:00
|
|
|
, fetchurl
|
2023-07-17 21:22:24 +00:00
|
|
|
, gnused
|
2023-07-17 03:28:13 +00:00
|
|
|
, jq
|
2023-07-17 22:19:29 +00:00
|
|
|
, lib
|
2023-07-17 22:27:49 +00:00
|
|
|
, newScope
|
2023-09-27 19:04:59 +00:00
|
|
|
, nix-update-script
|
2023-07-17 03:28:13 +00:00
|
|
|
, strip-nondeterminism
|
|
|
|
, unzip
|
|
|
|
, writeScript
|
|
|
|
, zip
|
2023-07-17 03:11:08 +00:00
|
|
|
}:
|
|
|
|
let
|
2023-07-17 22:19:29 +00:00
|
|
|
wrapAddon = addon: args:
|
2023-07-17 03:28:13 +00:00
|
|
|
let
|
|
|
|
extid = addon.passthru.extid;
|
2023-07-17 20:47:55 +00:00
|
|
|
# merge our requirements into the derivation args
|
|
|
|
args' = args // {
|
|
|
|
passthru = {
|
|
|
|
inherit extid;
|
|
|
|
original = addon;
|
|
|
|
} // (args.passthru or {});
|
|
|
|
nativeBuildInputs = [
|
2023-07-17 22:19:29 +00:00
|
|
|
jq
|
2023-07-17 20:47:55 +00:00
|
|
|
strip-nondeterminism
|
|
|
|
unzip
|
|
|
|
zip
|
|
|
|
] ++ (args.nativeBuildInputs or []);
|
|
|
|
};
|
2023-07-17 22:19:29 +00:00
|
|
|
in (stdenv.mkDerivation ({
|
2023-07-17 03:28:13 +00:00
|
|
|
# heavily borrows from <repo:nixos/nixpkgs:pkgs/build-support/fetchfirefoxaddon/default.nix>
|
2023-08-06 01:50:40 +00:00
|
|
|
name = "${addon.name}-wrapped";
|
2023-07-17 20:41:04 +00:00
|
|
|
unpackPhase = ''
|
2023-07-17 22:19:29 +00:00
|
|
|
echo "patching firefox addon $name into $out/${extid}.xpi"
|
2023-07-17 03:28:13 +00:00
|
|
|
|
2023-07-17 22:19:29 +00:00
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
# extract the XPI into the build directory
|
|
|
|
# it could be already wrapped, or a raw fetchurl result
|
|
|
|
unzip -q "${addon}/${extid}.xpi" -d . || \
|
|
|
|
unzip -q "${addon}" -d .
|
|
|
|
'';
|
|
|
|
|
|
|
|
patchPhase = ''
|
|
|
|
runHook prePatch
|
|
|
|
|
|
|
|
# firefox requires addons to have an id field when sideloading:
|
|
|
|
# - <https://extensionworkshop.com/documentation/publish/distribute-sideloading/>
|
2024-04-15 03:36:27 +00:00
|
|
|
for m in manifest.json manifest_v2.json manifest_v3.json; do
|
|
|
|
if test -e "$m"; then
|
|
|
|
NEW_MANIFEST=$(jq '. + {"applications": { "gecko": { "id": "${extid}" }}, "browser_specific_settings":{"gecko":{"id": "${extid}"}}}' "$m")
|
|
|
|
echo "$NEW_MANIFEST" > "$m"
|
|
|
|
fi
|
|
|
|
done
|
2023-07-17 22:19:29 +00:00
|
|
|
|
|
|
|
runHook postPatch
|
2023-07-17 20:41:04 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
2023-07-17 03:28:13 +00:00
|
|
|
# repackage the XPI
|
2023-07-17 21:22:24 +00:00
|
|
|
mkdir "$out"
|
2023-07-17 22:19:29 +00:00
|
|
|
zip -r -q -FS "$out/${extid}.xpi" ./*
|
|
|
|
strip-nondeterminism "$out/${extid}.xpi"
|
2023-07-17 20:41:04 +00:00
|
|
|
|
|
|
|
runHook postInstall
|
2023-07-17 03:28:13 +00:00
|
|
|
'';
|
2023-07-17 22:19:29 +00:00
|
|
|
} // args')).overrideAttrs (final: upstream: {
|
2023-07-17 03:28:13 +00:00
|
|
|
passthru = (upstream.passthru or {}) // {
|
2024-04-15 03:00:36 +00:00
|
|
|
unwrapped = addon;
|
2023-08-06 01:50:40 +00:00
|
|
|
withAttrs = attrs: wrapAddon addon (args // attrs);
|
2023-07-17 22:19:29 +00:00
|
|
|
withPostPatch = postPatch: final.passthru.withAttrs { inherit postPatch; };
|
2023-07-17 21:32:10 +00:00
|
|
|
# given an addon, repackage it without some `perm`ission
|
2023-07-17 22:19:29 +00:00
|
|
|
withoutPermission = perm: final.passthru.withPostPatch ''
|
2024-04-15 03:36:27 +00:00
|
|
|
for m in manifest.json manifest_v2.json manifest_v3.json; do
|
|
|
|
if test -e "$m"; then
|
|
|
|
NEW_MANIFEST=$(jq 'del(.permissions[] | select(. == "${perm}"))' "$m")
|
|
|
|
echo "$NEW_MANIFEST" > "$m"
|
|
|
|
fi
|
|
|
|
done
|
2023-07-17 21:32:10 +00:00
|
|
|
'';
|
2023-07-17 03:28:13 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2023-09-27 22:30:28 +00:00
|
|
|
# fetchAddon: fetch an addon directly from the mozilla store.
|
|
|
|
# prefer NOT to use this, because moz store doesn't offer versioned release access
|
|
|
|
# which breaks caching/reproducibility and such.
|
|
|
|
# (maybe the `latest.xpi` URL redirects to a versioned URI visible if i used curl?)
|
|
|
|
# fetchAddon = name: extid: hash: fetchurl {
|
|
|
|
# inherit name hash;
|
|
|
|
# url = "https://addons.mozilla.org/firefox/downloads/latest/${name}/latest.xpi";
|
|
|
|
# # extid can be found by unar'ing the above xpi, and copying browser_specific_settings.gecko.id field
|
|
|
|
# passthru = { inherit extid; };
|
|
|
|
# };
|
|
|
|
|
2023-09-27 22:13:43 +00:00
|
|
|
fetchVersionedAddon = { extid, version, url, hash ? "", pname ? extid }: stdenv.mkDerivation {
|
2023-09-27 22:06:38 +00:00
|
|
|
inherit pname version;
|
|
|
|
src = fetchurl {
|
|
|
|
inherit url hash;
|
|
|
|
};
|
|
|
|
dontUnpack = true;
|
|
|
|
installPhase = ''
|
|
|
|
cp $src $out
|
|
|
|
'';
|
|
|
|
|
2023-11-18 20:07:51 +00:00
|
|
|
passthru.updateScript = nix-update-script {
|
|
|
|
extraArgs = [
|
|
|
|
# uBlock mixes X.YY.ZbN and X.YY.ZrcN style.
|
|
|
|
# default nix-update accepts the former but rejects the later as unstable.
|
|
|
|
# that's problematic because beta releases later get pulled.
|
|
|
|
# ideally i'd reject both, but i don't know how.
|
|
|
|
"--version=unstable"
|
|
|
|
];
|
|
|
|
};
|
2023-09-27 22:06:38 +00:00
|
|
|
passthru.extid = extid;
|
|
|
|
};
|
|
|
|
|
2023-09-27 23:04:42 +00:00
|
|
|
in (lib.makeScope newScope (self: with self; {
|
2023-07-17 22:19:29 +00:00
|
|
|
unwrapped = lib.recurseIntoAttrs {
|
|
|
|
# get names from:
|
|
|
|
# - ~/ref/nix-community/nur-combined/repos/rycee/pkgs/firefox-addons/generated-firefox-addons.nix
|
|
|
|
# `wget ...xpi`; `unar ...xpi`; `cat */manifest.json | jq '.browser_specific_settings.gecko.id'`
|
|
|
|
browserpass-extension = callPackage ./browserpass-extension { };
|
2023-07-18 20:21:48 +00:00
|
|
|
bypass-paywalls-clean = callPackage ./bypass-paywalls-clean { };
|
2024-01-03 13:33:32 +00:00
|
|
|
ctrl-shift-c-should-copy = callPackage ./ctrl-shift-c-should-copy { };
|
2024-04-15 03:00:36 +00:00
|
|
|
i-still-dont-care-about-cookies = callPackage ./i-still-dont-care-about-cookies { };
|
2024-02-18 06:14:49 +00:00
|
|
|
open-in-mpv = callPackage ./open-in-mpv { };
|
2023-09-27 19:04:59 +00:00
|
|
|
|
2023-09-27 22:26:55 +00:00
|
|
|
ether-metamask = fetchVersionedAddon rec {
|
|
|
|
extid = "webextension@metamask.io";
|
|
|
|
pname = "ether-metamask";
|
|
|
|
url = "https://github.com/MetaMask/metamask-extension/releases/download/v${version}/metamask-firefox-${version}.zip";
|
2024-04-15 02:35:49 +00:00
|
|
|
version = "11.14.0";
|
|
|
|
hash = "sha256-VXfJndT+MDEPbIJGjyCxdbMtwPRojgxjwQdY59ygZGc=";
|
2023-09-27 22:26:55 +00:00
|
|
|
};
|
2023-12-13 20:51:57 +00:00
|
|
|
fx_cast = fetchVersionedAddon rec {
|
|
|
|
extid = "fx_cast@matt.tf";
|
|
|
|
pname = "fx_cast";
|
|
|
|
url = "https://github.com/hensm/fx_cast/releases/download/v${version}/fx_cast-${version}.xpi";
|
|
|
|
version = "0.3.1";
|
|
|
|
hash = "sha256-zaYnUJpJkRAPSCpM3S20PjMS4aeBtQGhXB2wgdlFkSQ=";
|
|
|
|
};
|
2023-09-27 22:24:04 +00:00
|
|
|
i2p-in-private-browsing = fetchVersionedAddon rec {
|
|
|
|
extid = "i2ppb@eyedeekay.github.io";
|
|
|
|
pname = "i2p-in-private-browsing";
|
|
|
|
url = "https://github.com/eyedeekay/I2P-in-Private-Browsing-Mode-Firefox/releases/download/${version}/i2ppb@eyedeekay.github.io.xpi";
|
2024-01-16 19:10:32 +00:00
|
|
|
version = "1.49";
|
2023-09-27 22:24:04 +00:00
|
|
|
hash = "sha256-LnR5z3fqNJywlr/khFdV4qloKGQhbxNZQvWCEgz97DU=";
|
|
|
|
};
|
2023-09-27 22:17:02 +00:00
|
|
|
sidebery = fetchVersionedAddon rec {
|
|
|
|
extid = "{3c078156-979c-498b-8990-85f7987dd929}";
|
|
|
|
pname = "sidebery";
|
2024-02-26 18:07:45 +00:00
|
|
|
url = let
|
|
|
|
versionPrefix = lib.concatStringsSep "." (lib.take 3 (lib.splitVersion version));
|
|
|
|
in "https://github.com/mbnuqw/sidebery/releases/download/v${versionPrefix}/sidebery-${version}.xpi";
|
2024-04-15 03:36:03 +00:00
|
|
|
version = "5.2.0.7";
|
|
|
|
hash = "sha256-vbMicJc8c6njx6Rn8TIEktoHSZDzoUr29uX9iFapy0w=";
|
2023-09-27 22:17:02 +00:00
|
|
|
};
|
2023-09-27 22:06:38 +00:00
|
|
|
sponsorblock = fetchVersionedAddon rec {
|
|
|
|
extid = "sponsorBlocker@ajay.app";
|
2023-09-27 19:04:59 +00:00
|
|
|
pname = "sponsorblock";
|
2023-09-27 22:06:38 +00:00
|
|
|
url = "https://github.com/ajayyy/SponsorBlock/releases/download/${version}/FirefoxSignedInstaller.xpi";
|
2024-03-22 16:27:23 +00:00
|
|
|
version = "5.5.9";
|
|
|
|
hash = "sha256-lyBrszbjdfMOWZbYwE6DjNtM8wq0Vv1eCcobBKNelWw=";
|
2023-09-27 19:04:59 +00:00
|
|
|
};
|
2023-09-27 22:13:43 +00:00
|
|
|
ublacklist = fetchVersionedAddon rec {
|
|
|
|
extid = "@ublacklist";
|
|
|
|
pname = "ublacklist";
|
|
|
|
url = "https://github.com/iorate/ublacklist/releases/download/v${version}/ublacklist-v${version}-firefox.zip";
|
2024-03-04 08:18:48 +00:00
|
|
|
version = "8.5.1";
|
|
|
|
hash = "sha256-GLBB/in/RY2AQWph7/O5cQQEXZN9W9tJS/kqUD2IEck=";
|
2023-09-27 22:13:43 +00:00
|
|
|
};
|
2023-09-27 22:21:42 +00:00
|
|
|
ublock-origin = fetchVersionedAddon rec {
|
|
|
|
extid = "uBlock0@raymondhill.net";
|
|
|
|
pname = "ublock-origin";
|
|
|
|
# N.B.: a handful of versions are released unsigned
|
|
|
|
# url = "https://github.com/gorhill/uBlock/releases/download/${version}/uBlock0_${version}.signed.xpi";
|
|
|
|
url = "https://github.com/gorhill/uBlock/releases/download/${version}/uBlock0_${version}.firefox.signed.xpi";
|
2024-04-15 02:35:49 +00:00
|
|
|
version = "1.57.3b3";
|
|
|
|
hash = "sha256-mwSikDhqNt7h6CMOowooaxrEpZca62YDmOhmC72K9co=";
|
2023-09-27 22:21:42 +00:00
|
|
|
};
|
2023-07-17 22:19:29 +00:00
|
|
|
};
|
2023-09-27 23:04:42 +00:00
|
|
|
})).overrideScope (self: super:
|
|
|
|
let
|
|
|
|
wrapped = lib.mapAttrs (name: _value: wrapAddon self.unwrapped."${name}" {}) super.unwrapped;
|
|
|
|
in wrapped // {
|
|
|
|
browserpass-extension = wrapped.browserpass-extension.withoutPermission "notifications";
|
|
|
|
sponsorblock = wrapped.sponsorblock.withPostPatch ''
|
2023-07-17 21:32:10 +00:00
|
|
|
# patch sponsorblock to not show the help tab on first launch.
|
2023-09-11 22:30:28 +00:00
|
|
|
#
|
2023-07-17 21:32:10 +00:00
|
|
|
# XXX: i tried to build sponsorblock from source and patch this *before* it gets webpack'd,
|
|
|
|
# but web shit is absolutely cursed and building from source requires a fucking PhD
|
|
|
|
# (if you have one, feel free to share your nix package)
|
2023-09-11 22:30:28 +00:00
|
|
|
#
|
2023-12-13 17:37:48 +00:00
|
|
|
# NB: in source this is `alreadyInstalled: false`, but the build process hates Booleans or something
|
2024-03-24 12:49:18 +00:00
|
|
|
# TODO(2024/03/23): this is broken (replacement doesn't match). but maybe not necessary anymore?
|
2023-12-13 17:37:48 +00:00
|
|
|
substituteInPlace js/*.js \
|
|
|
|
--replace 'alreadyInstalled:!1' 'alreadyInstalled:!0'
|
2023-07-17 21:32:10 +00:00
|
|
|
'';
|
2023-09-27 23:04:42 +00:00
|
|
|
}
|
|
|
|
)
|