From ed4c27a90116baa5c78562394e8196806a6c37a1 Mon Sep 17 00:00:00 2001 From: SebastianStork Date: Tue, 10 Feb 2026 19:52:43 +0100 Subject: [PATCH] firefox: Refactor extension configuration --- modules/home/programs/firefox.nix | 99 +++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 25 deletions(-) diff --git a/modules/home/programs/firefox.nix b/modules/home/programs/firefox.nix index 50b7087..6e504cf 100644 --- a/modules/home/programs/firefox.nix +++ b/modules/home/programs/firefox.nix @@ -5,10 +5,72 @@ lib, ... }: -{ - options.custom.programs.firefox.enable = lib.mkEnableOption ""; +let + cfg = config.custom.programs.firefox; + + mkExtension = + { + name, + uuid, + defaultArea, + ... + }: + { + name = uuid; + value = { + install_url = "file:///${ + inputs.firefox-addons.packages.${pkgs.stdenv.hostPlatform.system}.${name} + }/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/${uuid}.xpi"; + installation_mode = "force_installed"; + default_area = defaultArea; + }; + }; +in +{ + options.custom.programs.firefox = { + enable = lib.mkEnableOption ""; + extensions = lib.mkOption { + type = lib.types.attrsOf ( + lib.types.submodule ( + { name, ... }: + { + options = { + enable = lib.mkEnableOption "" // { + default = true; + }; + name = lib.mkOption { + type = lib.types.nonEmptyStr; + default = name; + }; + uuid = lib.mkOption { + type = lib.types.nonEmptyStr; + default = ""; + }; + defaultArea = lib.mkOption { + type = lib.types.enum [ + "menupanel" + "navbar" + ]; + default = "menupanel"; + }; + }; + } + ) + ); + default = { }; + }; + }; + + config = lib.mkIf cfg.enable { + custom.programs.firefox.extensions = { + dictionary-german.uuid = "de-DE@dictionaries.addons.mozilla.org"; + ublock-origin.uuid = "uBlock0@raymondhill.net"; + bitwarden.uuid = "{446900e4-71c2-419f-a6a7-df9c091e268b}"; + return-youtube-dislikes.uuid = "{762f9885-5a13-4abd-9c77-433dcd38b8fd}"; + sponsorblock.uuid = "sponsorBlocker@ajay.app"; + clearurls.uuid = "{74145f27-f039-47ce-a470-a662b129930a}"; + }; - config = lib.mkIf config.custom.programs.firefox.enable { programs.firefox = { enable = true; @@ -40,29 +102,16 @@ }; policies.ExtensionSettings = - let - extension = shortId: uuid: { - name = uuid; - value = { - install_url = "file:///${ - inputs.firefox-addons.packages.${pkgs.stdenv.hostPlatform.system}.${shortId} - }/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/${uuid}.xpi"; - installation_mode = "force_installed"; - default_area = "menupanel"; - }; - }; - in - { + ( + cfg.extensions + |> lib.attrValues + |> lib.filter ({ enable, ... }: enable) + |> lib.map mkExtension + |> lib.listToAttrs + ) + // { "*".installation_mode = "blocked"; - } - // lib.listToAttrs [ - (extension "dictionary-german" "de-DE@dictionaries.addons.mozilla.org") - (extension "ublock-origin" "uBlock0@raymondhill.net") - (extension "bitwarden" "{446900e4-71c2-419f-a6a7-df9c091e268b}") - (extension "return-youtube-dislikes" "{762f9885-5a13-4abd-9c77-433dcd38b8fd}") - (extension "sponsorblock" "sponsorBlocker@ajay.app") - (extension "clearurls" "{74145f27-f039-47ce-a470-a662b129930a}") - ]; + }; }; }; }