firefox-extensions: make the patching logic even more pluggable
This commit is contained in:
@@ -9,34 +9,41 @@
|
|||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
# given an addon, repackage it without some `perm`ission
|
# given an addon, repackage it without some `perm`ission
|
||||||
removePermission = perm: addon:
|
removePermission = perm: addon: mkPatchedAddon addon {
|
||||||
|
patchPhase = ''
|
||||||
|
NEW_MANIFEST=$(jq 'del(.permissions[] | select(. == "${perm}"))' "$out/$UUID/manifest.json")
|
||||||
|
echo "$NEW_MANIFEST" > "$out/$UUID/manifest.json"
|
||||||
|
'';
|
||||||
|
nativeBuildInputs = [ jq ];
|
||||||
|
};
|
||||||
|
|
||||||
|
mkPatchedAddon = addon: args:
|
||||||
let
|
let
|
||||||
extid = addon.passthru.extid;
|
extid = addon.passthru.extid;
|
||||||
in stdenv.mkDerivation {
|
# merge our requirements into the derivation args
|
||||||
# heavily borrows from <repo:nixos/nixpkgs:pkgs/build-support/fetchfirefoxaddon/default.nix>
|
args' = args // {
|
||||||
inherit (addon) name;
|
|
||||||
passthru = {
|
passthru = {
|
||||||
inherit extid;
|
inherit extid;
|
||||||
original = addon;
|
original = addon;
|
||||||
|
} // (args.passthru or {});
|
||||||
|
nativeBuildInputs = [
|
||||||
|
strip-nondeterminism
|
||||||
|
unzip
|
||||||
|
zip
|
||||||
|
] ++ (args.nativeBuildInputs or []);
|
||||||
};
|
};
|
||||||
|
in stdenv.mkDerivation ({
|
||||||
|
# heavily borrows from <repo:nixos/nixpkgs:pkgs/build-support/fetchfirefoxaddon/default.nix>
|
||||||
|
inherit (addon) name;
|
||||||
unpackPhase = ''
|
unpackPhase = ''
|
||||||
UUID="${extid}"
|
UUID="${extid}"
|
||||||
echo "firefox addon $name into $out/$UUID.xpi, remove ${perm}"
|
echo "patching firefox addon $name into $out/$UUID.xpi"
|
||||||
|
|
||||||
# extract the XPI
|
# extract the XPI
|
||||||
mkdir -p "$out/$UUID"
|
mkdir -p "$out/$UUID"
|
||||||
unzip -q "${addon}/$UUID.xpi" -d "$out/$UUID"
|
unzip -q "${addon}/$UUID.xpi" -d "$out/$UUID"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
patchPhase = ''
|
|
||||||
runHook prePatch
|
|
||||||
|
|
||||||
NEW_MANIFEST=$(jq 'del(.permissions[] | select(. == "${perm}"))' "$out/$UUID/manifest.json")
|
|
||||||
echo "$NEW_MANIFEST" > "$out/$UUID/manifest.json"
|
|
||||||
|
|
||||||
runHook postPatch
|
|
||||||
'';
|
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
runHook preInstall
|
runHook preInstall
|
||||||
|
|
||||||
@@ -48,14 +55,7 @@ let
|
|||||||
|
|
||||||
runHook postInstall
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
} // args');
|
||||||
nativeBuildInputs = [
|
|
||||||
jq
|
|
||||||
strip-nondeterminism
|
|
||||||
unzip
|
|
||||||
zip
|
|
||||||
];
|
|
||||||
};
|
|
||||||
# given an addon, add a `passthru.withoutPermission` method for further configuration
|
# given an addon, add a `passthru.withoutPermission` method for further configuration
|
||||||
mkConfigurable = pkg: pkg.overrideAttrs (final: upstream: {
|
mkConfigurable = pkg: pkg.overrideAttrs (final: upstream: {
|
||||||
passthru = (upstream.passthru or {}) // {
|
passthru = (upstream.passthru or {}) // {
|
||||||
|
Reference in New Issue
Block a user