git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #106000 from Luis-Hebendanz/firefoxWrapperAddonSettings

firefox: wrapper updating an addon perserves addon settings

commit00b8fa792b2d39ef1b42848059ff15d50341decc authorLassulus <github@lassul.us> dateTue 15 Dec 2020, 22:16 (6 years ago) parentde8205f1c8c134
3 files changed+29−19
doc/builders/packages/firefox.section.md+2−2 pkgs/applications/networking/browsers/firefox/wrapper.nix+21−14 pkgs/build-support/fetchfirefoxaddon/default.nix+6−3
doc/builders/packages/firefox.section.md+2−2
@@ -9,7 +9,7 @@ The `wrapFirefox` function allows to pass policies, preferences and extension th
99 myFirefox = wrapFirefox firefox-unwrapped {
1010 nixExtensions = [
1111 (fetchFirefoxAddon {
12− name = "ublock";
12+ name = "ublock"; # Has to be unique!
1313 url = "https://addons.mozilla.org/firefox/downloads/file/3679754/ublock_origin-1.31.0-an+fx.xpi";
1414 sha256 = "1h768ljlh3pi23l27qp961v1hd0nbj2vasgy11bmcrlqp40zgvnr";
1515 })
@@ -42,7 +42,7 @@ The `wrapFirefox` function allows to pass policies, preferences and extension th
4242If `nixExtensions != null` then all manually installed addons will be uninstalled from your browser profile.
4343To view available enterprise policies visit [enterprise policies](https://github.com/mozilla/policy-templates#enterprisepoliciesenabled)
4444or type into the Firefox url bar: `about:policies#documentation`.
45−Nix installed addons do not have a valid signature, which is why signature verification is disabled. This does not compromise security because downloaded addons are checksumed and manual addons can't be installed.
45+Nix installed addons do not have a valid signature, which is why signature verification is disabled. This does not compromise security because downloaded addons are checksumed and manual addons can't be installed. Also make sure that the `name` field of fetchFirefoxAddon is unique. If you remove an addon from the nixExtensions array, rebuild and start Firefox the removed addon will be completly removed with all of its settings.
4646
4747## Troubleshooting {#sec-firefox-troubleshooting}
4848If addons do not appear installed although they have been defined in your nix configuration file reset the local addon state of your Firefox profile by clicking `help -> restart with addons disabled -> restart -> refresh firefox`. This can happen if you switch from manual addon mode to nix addon mode and then back to manual mode and then again to nix addon mode.
pkgs/applications/networking/browsers/firefox/wrapper.nix+21−14
@@ -1,5 +1,5 @@
11{ stdenv, lib, makeDesktopItem, makeWrapper, lndir, config
2−, replace, fetchurl, zip, unzip, jq, xdg_utils
2+, replace, fetchurl, zip, unzip, jq, xdg_utils, writeText
33
44## various stuff that can be plugged in
55, flashplayer, hal-flash
@@ -97,12 +97,17 @@ let
9797 # EXTRA PREF CHANGES #
9898 # #
9999 #########################
100− policiesJson = builtins.toFile "policies.json"
101− (builtins.toJSON enterprisePolicies);
100+ policiesJson = writeText "policies.json" (builtins.toJSON enterprisePolicies);
102101
103102 usesNixExtensions = nixExtensions != null;
104103
105− extensions = builtins.map (a:
104+ nameArray = builtins.map(a: a.name) (if usesNixExtensions then nixExtensions else []);
105+
106+ # Check that every extension has a unqiue .name attribute
107+ # and an extid attribute
108+ extensions = if nameArray != (lib.unique nameArray) then
109+ throw "Firefox addon name needs to be unique"
110+ else builtins.map (a:
106111 if ! (builtins.hasAttr "extid" a) then
107112 throw "nixExtensions has an invalid entry. Missing extid attribute. Please use fetchfirefoxaddon"
108113 else
@@ -128,12 +133,19 @@ let
128133 };
129134 }
130135 ) {} extensions;
131− }
136+ } //
137+ {
138+ Extensions = {
139+ Install = lib.foldr (e: ret:
140+ ret ++ [ "${e.outPath}/${e.extid}.xpi" ]
141+ ) [] extensions;
142+ };
143+ }
132144 // extraPolicies;
133145 };
134146
135− mozillaCfg = builtins.toFile "mozilla.cfg" ''
136−// First line must be a comment
147+ mozillaCfg = writeText "mozilla.cfg" ''
148+ // First line must be a comment
137149
138150 // Disables addon signature checking
139151 // to be able to install addons that do not have an extid
@@ -320,18 +332,13 @@ let
320332 # preparing for autoconfig
321333 mkdir -p "$out/lib/${firefoxLibName}/defaults/pref"
322334
323− cat > "$out/lib/${firefoxLibName}/defaults/pref/autoconfig.js" <<EOF
324− pref("general.config.filename", "mozilla.cfg");
325− pref("general.config.obscure_value", 0);
326− EOF
335+ echo 'pref("general.config.filename", "mozilla.cfg");' > "$out/lib/${firefoxLibName}/defaults/pref/autoconfig.js"
336+ echo 'pref("general.config.obscure_value", 0);' >> "$out/lib/${firefoxLibName}/defaults/pref/autoconfig.js"
327337
328338 cat > "$out/lib/${firefoxLibName}/mozilla.cfg" < ${mozillaCfg}
329339
330340 mkdir -p $out/lib/${firefoxLibName}/distribution/extensions
331341
332− for i in ${toString extensions}; do
333− ln -s -t $out/lib/${firefoxLibName}/distribution/extensions $i/*
334− done
335342 #############################
336343 # #
337344 # END EXTRA PREF CHANGES #
pkgs/build-support/fetchfirefoxaddon/default.nix+6−3
@@ -1,16 +1,20 @@
11{stdenv, lib, coreutils, unzip, jq, zip, fetchurl,writeScript, ...}:
2−{ name
2+
3+{
4+ name
35, url
46, md5 ? ""
57, sha1 ? ""
68, sha256 ? ""
79, sha512 ? ""
10+, fixedExtid ? null
811, hash ? ""
912}:
13+
1014stdenv.mkDerivation rec {
1115
1216 inherit name;
13− extid = "${src.outputHash}@${name}";
17+ extid = if fixedExtid == null then "nixos@${name}" else fixedExtid;
1418 passthru = {
1519 exitd=extid;
1620 };
@@ -35,4 +39,3 @@ stdenv.mkDerivation rec {
3539 };
3640 nativeBuildInputs = [ coreutils unzip zip jq ];
3741}
38−