diff options
| author | Seth Flynn <[email protected]> | 2025-01-29 13:52:32 -0500 |
|---|---|---|
| committer | Seth Flynn <[email protected]> | 2025-01-29 13:52:32 -0500 |
| commit | 8126a8ab097699269a558d5972a0e0dd6f2c98d2 (patch) | |
| tree | 2eff0c4d1c75abdc5f1dd067b7510986d357f4d1 | |
| parent | 46f1cf5b41e06a833c2521a3eb2b71c6fcbc2f46 (diff) | |
firefox-addons: initfirefox-addons
| -rw-r--r-- | flake.nix | 29 | ||||
| -rw-r--r-- | pkgs/fetchFirefoxAddon/package.nix | 85 | ||||
| -rw-r--r-- | pkgs/firefox-addons/ublock.nix | 9 | ||||
| -rw-r--r-- | pkgs/firefoxAddonUpdateScript/package.nix | 32 | ||||
| -rw-r--r-- | pkgs/firefoxAddonUpdateScript/script.sh | 29 | ||||
| -rw-r--r-- | update-addons.nix | 30 |
6 files changed, 204 insertions, 10 deletions
@@ -52,16 +52,25 @@ getchpkgs = import ./default.nix { inherit pkgs; }; - getchpkgs' = lib.filterAttrs (lib.const ( - deriv: - let - isCross = deriv.stdenv.buildPlatform != deriv.stdenv.hostPlatform; - availableOnHost = lib.meta.availableOn pkgs.stdenv.hostPlatform deriv; - # `nix flake check` doesn't like broken packages - isBroken = deriv.meta.broken or false; - in - isCross || availableOnHost && (!isBroken) - )) getchpkgs; + getchpkgs' = + # Find valid installables + lib.filterAttrs + (lib.const ( + deriv: + let + isCross = deriv.stdenv.buildPlatform != deriv.stdenv.hostPlatform; + availableOnHost = lib.meta.availableOn pkgs.stdenv.hostPlatform deriv; + # `nix flake check` doesn't like broken packages + isBroken = deriv.meta.broken or false; + isFunction = lib.isFunction deriv; + in + (!isFunction) && (isCross || availableOnHost) && (!isBroken) + )) + # Flatten `firefox-addons` package set + ( + lib.removeAttrs getchpkgs [ "firefox-addons" ] + // lib.mapAttrs' (name: lib.nameValuePair "firefox-addons-${name}") getchpkgs.firefox-addons + ); in getchpkgs' // { default = getchpkgs'.treefetch or pkgs.emptyFile; } diff --git a/pkgs/fetchFirefoxAddon/package.nix b/pkgs/fetchFirefoxAddon/package.nix new file mode 100644 index 0000000..283e92c --- /dev/null +++ b/pkgs/fetchFirefoxAddon/package.nix @@ -0,0 +1,85 @@ +{ + lib, + stdenvNoCC, + fetchurl, +}: + +lib.makeOverridable ( + lib.fetchers.withNormalizedHash { } ( + { + url, + addonId ? null, + addonSlug ? args.pname or null, + firefoxVendor ? "mozilla", + # Keep in sync with https://github.com/nix-community/home-manager/blob/e1ae908bcc30af792b0bb0a52e53b03d2577255e/modules/programs/firefox/mkFirefoxModule.nix#L52-L54 + extensionPath ? "extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", + outputHash, + outputHashAlgo, + ... + }@args: + + assert lib.assertMsg ( + addonId != null || addonSlug != null + ) "One of `addonId` or `addonSlug` must be passed"; + + let + addonRef = if addonId != null then addonId else addonSlug; + + knownArgs = [ + "url" + "addonId" + "firefoxVendor" + "extensionPath" + "outputHash" + "outputHashAlgo" + ]; + in + + stdenvNoCC.mkDerivation ( + finalAttrs: + lib.removeAttrs args knownArgs + // { + name = + "firefox-addons" + + lib.optionalString ( + finalAttrs ? "pname" && finalAttrs ? "version" + ) "-${finalAttrs.pname}-${finalAttrs.version}"; + + src = fetchurl { + inherit url outputHash outputHashAlgo; + }; + + dontConfigure = args.dontConfigure or true; + dontBuild = args.dontBuild or true; + + installPhase = + args.installPhase or '' + runHook preInstall + + extensionDir=$out/share/${firefoxVendor}/${extensionPath} + install -d $extensionDir + install -Dm644 $src $extensionDir + + runHook postInstall + ''; + + preferLocalBuild = args.preferLocalBuild or true; + impureEnvVars = lib.fetchers.proxyImpureEnvVars; + + passthru = args.passthru or { } // { + inherit + addonId + addonRef + addonSlug + extensionPath + firefoxVendor + ; + }; + + meta = args.meta or { } // { + position = builtins.unsafeGetAttrPos "url" args; + }; + } + ) + ) +) diff --git a/pkgs/firefox-addons/ublock.nix b/pkgs/firefox-addons/ublock.nix new file mode 100644 index 0000000..ad7e4c9 --- /dev/null +++ b/pkgs/firefox-addons/ublock.nix @@ -0,0 +1,9 @@ +{ fetchFirefoxAddon }: + +fetchFirefoxAddon { + pname = "ublock-origin"; + version = "1.62.0"; + + url = "https://addons.mozilla.org/firefox/downloads/file/4412673/ublock_origin-1.62.0.xpi"; + hash = "sha256-ip4CqoOMMC+xTitbyIpgNtNjWKrdb5UWihRa8gGO8aM="; +} diff --git a/pkgs/firefoxAddonUpdateScript/package.nix b/pkgs/firefoxAddonUpdateScript/package.nix new file mode 100644 index 0000000..9590caa --- /dev/null +++ b/pkgs/firefoxAddonUpdateScript/package.nix @@ -0,0 +1,32 @@ +{ + lib, + common-updater-scripts, + curl, + jq, + writeShellApplication, +}: + +let + script = writeShellApplication { + name = "firefox-addon-update-script"; + + runtimeInputs = [ + common-updater-scripts + curl + jq + ]; + + text = lib.fileContents ./script.sh; + }; +in + +{ + addonRef, + attrPath, +}: + +[ + (lib.getExe script) + attrPath + addonRef +] diff --git a/pkgs/firefoxAddonUpdateScript/script.sh b/pkgs/firefoxAddonUpdateScript/script.sh new file mode 100644 index 0000000..1d13cac --- /dev/null +++ b/pkgs/firefoxAddonUpdateScript/script.sh @@ -0,0 +1,29 @@ +# shellcheck shell=bash + +readonly AMO_API="https://addons.mozilla.org/api/v5" +readonly ADDON_ENDPOINT="/addons/addon" + +attribute="${1:-}" +addon_ref="${2:-}" + +usage() { + echo " +usage: $0 <attribute> <addon_ref> +" +} + +bail() { + usage + exit 1 +} + +if [[ -z $attribute ]] || [[ -z $addon_ref ]]; then + bail +fi + +data="$(curl -sSL "$AMO_API/$ADDON_ENDPOINT/$addon_ref")" + +url="$(jq -r '.current_version.file.url' <<<"$data")" +version="$(jq -r '.current_version.version' <<<"$data")" + +update-source-version "$attribute" "$version" "" "$url" diff --git a/update-addons.nix b/update-addons.nix new file mode 100644 index 0000000..994245a --- /dev/null +++ b/update-addons.nix @@ -0,0 +1,30 @@ +{ + pkgs ? import <nixpkgs> { + inherit system; + config = { }; + overlays = [ ]; + }, + system ? builtins.currentSystem, +}: + +let + inherit (pkgs) lib; + + getchpkgs = import ./default.nix { inherit pkgs; }; +in + +pkgs.writeShellApplication { + name = "update-firefox-addons"; + + text = lib.concatLines ( + lib.mapAttrsToList ( + pname: drv: + lib.escapeShellArgs ( + getchpkgs.firefoxAddonUpdateScript { + attrPath = "firefox-addons.${pname}"; + inherit (drv.passthru) addonRef; + } + ) + ) getchpkgs.firefox-addons + ); +} |
