Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firefox wrapper preserve addon settings #105985

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/builders/packages/firefox.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The `wrapFirefox` function allows to pass policies, preferences and extension th
myFirefox = wrapFirefox firefox-unwrapped {
nixExtensions = [
(fetchFirefoxAddon {
name = "ublock";
name = "ublock"; # Has to be unique!
url = "https://addons.mozilla.org/firefox/downloads/file/3679754/ublock_origin-1.31.0-an+fx.xpi";
sha256 = "1h768ljlh3pi23l27qp961v1hd0nbj2vasgy11bmcrlqp40zgvnr";
})
Expand Down Expand Up @@ -42,7 +42,7 @@ The `wrapFirefox` function allows to pass policies, preferences and extension th
If `nixExtensions != null` then all manually installed addons will be uninstalled from your browser profile.
To view available enterprise policies visit [enterprise policies](https://github.com/mozilla/policy-templates#enterprisepoliciesenabled)
or type into the Firefox url bar: `about:policies#documentation`.
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.
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.

## Troubleshooting {#sec-firefox-troubleshooting}
If 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.
Expand Down
46 changes: 30 additions & 16 deletions pkgs/applications/networking/browsers/firefox/wrapper.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ stdenv, lib, makeDesktopItem, makeWrapper, lndir, config
, replace, fetchurl, zip, unzip, jq
, replace, fetchurl, zip, unzip, jq, writeTextFile

## various stuff that can be plugged in
, flashplayer, hal-flash
Expand Down Expand Up @@ -97,18 +97,27 @@ let
# EXTRA PREF CHANGES #
# #
#########################
policiesJson = builtins.toFile "policies.json"
(builtins.toJSON enterprisePolicies);
policiesJson = writeTextFile {
name = "policies.json";
text = (builtins.toJSON enterprisePolicies);
};

usesNixExtensions = nixExtensions != null;

extensions = builtins.map (a:
nameArray = builtins.map(a: a.name) (if usesNixExtensions then nixExtensions else []);

extensions = if nameArray != (lib.unique nameArray) then
throw "Firefox addon name needs to be unique"
else builtins.map (a:
if ! (builtins.hasAttr "extid" a) then
throw "nixExtensions has an invalid entry. Missing extid attribute. Please use fetchfirefoxaddon"
else
a
) (if usesNixExtensions then nixExtensions else []);

# Check that every extension has a unqiue .name attribute
checkUnique = if extensions != (lib.unique extensions) then throw "Firefox extension names have to be unique" else {};

enterprisePolicies =
{
policies = lib.optionalAttrs usesNixExtensions {
Expand All @@ -128,7 +137,14 @@ let
};
}
) {} extensions;
}
} //
{
Extensions = {
Install = lib.foldr (e: ret:
ret ++ [ "${e.outPath}/${e.extid}.xpi" ]
) [] extensions;
};
}
// extraPolicies;
};

Expand Down Expand Up @@ -176,10 +192,10 @@ let


buildCommand = lib.optionalString stdenv.isDarwin ''
mkdir -p $out/Applications
cp -R --no-preserve=mode,ownership ${browser}/Applications/${browserName}.app $out/Applications
rm -f $out${browser.execdir or "/bin"}/${browserName}
'' + ''
mkdir -p $out/Applications
cp -R --no-preserve=mode,ownership ${browser}/Applications/${browserName}.app $out/Applications
rm -f $out${browser.execdir or "/bin"}/${browserName}
'' + ''
if [ ! -x "${browser}${browser.execdir or "/bin"}/${browserName}" ]
then
echo "cannot find executable file \`${browser}${browser.execdir or "/bin"}/${browserName}'"
Expand Down Expand Up @@ -319,18 +335,16 @@ let
# preparing for autoconfig
mkdir -p "$out/lib/${firefoxLibName}/defaults/pref"

cat > "$out/lib/${firefoxLibName}/defaults/pref/autoconfig.js" <<EOF
pref("general.config.filename", "mozilla.cfg");
pref("general.config.obscure_value", 0);
EOF
echo 'pref("general.config.filename", "mozilla.cfg");' >> "$out/lib/${firefoxLibName}/defaults/pref/autoconfig.js"
echo 'pref("general.config.obscure_value", 0);' >> "$out/lib/${firefoxLibName}/defaults/pref/autoconfig.js"

cat > "$out/lib/${firefoxLibName}/mozilla.cfg" < ${mozillaCfg}

mkdir -p $out/lib/${firefoxLibName}/distribution/extensions

for i in ${toString extensions}; do
ln -s -t $out/lib/${firefoxLibName}/distribution/extensions $i/*
done
# for i in ${toString extensions}; do
# ln -s -t $out/lib/${firefoxLibName}/distribution/extensions $i/*
# done
#############################
# #
# END EXTRA PREF CHANGES #
Expand Down
9 changes: 7 additions & 2 deletions pkgs/build-support/fetchfirefoxaddon/default.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{stdenv, lib, coreutils, unzip, jq, zip, fetchurl,writeScript, ...}:
{ name
let

in
{
name
, url
, md5 ? ""
, sha1 ? ""
, sha256 ? ""
, sha512 ? ""
}:

stdenv.mkDerivation rec {

inherit name;
extid = "${src.outputHash}@${name}";
extid = "12345@${name}";
passthru = {
exitd=extid;
};
Expand Down