diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 6a5cce7e0..9fe4f59af 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1381,6 +1381,32 @@ in A new module is available: 'services.lieer'. ''; } + + { + time = "2020-03-15T16:55:28+00:00"; + condition = config.programs.firefox.enable; + message = '' + In anticipation of Firefox dropping support for extension + sideloading[1], we now install extensions directly to + Firefox profiles managed through Home Manager's + + 'programs.firefox.profiles' + + option. + + Unfortunately this will most likely trigger an "Existing + file is in the way" error when activating your configuration + since Firefox keeps a copy of the add-on in the location + Home Manager wants to overwrite. If this is the case, remove + the listed '.xpi' files and try again. + + This change also means that extensions installed through + Home Manager may disappear from unmanaged profiles in future + Firefox releases. + + [1] https://blog.mozilla.org/addons/2019/10/31/firefox-to-discontinue-sideloaded-extensions/ + ''; + } ]; }; } diff --git a/modules/programs/firefox.nix b/modules/programs/firefox.nix index 7f2367eb0..0c4645ab0 100644 --- a/modules/programs/firefox.nix +++ b/modules/programs/firefox.nix @@ -23,8 +23,15 @@ let then "${firefoxConfigPath}/Profiles" else firefoxConfigPath; + # The extensions path shared by all profiles; will not be supported + # by future Firefox versions. extensionPath = "extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"; + extensionsEnvPkg = pkgs.buildEnv { + name = "hm-firefox-extensions"; + paths = cfg.extensions; + }; + profiles = flip mapAttrs' cfg.profiles (_: profile: nameValuePair "Profile${toString profile.id}" { @@ -283,17 +290,10 @@ in home.file = mkMerge ( [{ - "${mozillaConfigPath}/${extensionPath}" = mkIf (cfg.extensions != []) ( - let - extensionsEnv = pkgs.buildEnv { - name = "hm-firefox-extensions"; - paths = cfg.extensions; - }; - in { - source = "${extensionsEnv}/share/mozilla/${extensionPath}"; - recursive = true; - } - ); + "${mozillaConfigPath}/${extensionPath}" = mkIf (cfg.extensions != []) { + source = "${extensionsEnvPkg}/share/mozilla/${extensionPath}"; + recursive = true; + }; "${firefoxConfigPath}/profiles.ini" = mkIf (cfg.profiles != {}) { text = profilesIni; @@ -314,6 +314,11 @@ in mkIf (profile.settings != {} || profile.extraConfig != "") { text = mkUserJs profile.settings profile.extraConfig; }; + + "${profilesPath}/${profile.path}/extensions" = mkIf (cfg.extensions != []) { + source = "${extensionsEnvPkg}/share/mozilla/${extensionPath}"; + recursive = true; + }; }) ); };