nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.88k stars 1.79k forks source link

Firefox configuration tracking issue (+Thunderbird?) #606

Open deliciouslytyped opened 5 years ago

deliciouslytyped commented 5 years ago

I hope this is an appropriate place for this. A bit of a brain dump till further notice, I've heard of people working on this but only by proxy so...:

References: [all being researched, will be cleaned later, inconsistencies likely] Nixpkgs issues:

Upstream (firefox):

,

Note:

TODO: check bugzilla (mostly relating to "autoconfig", just for starters there are some interesting things here https://bugzilla.mozilla.org/show_bug.cgi?id=1455601

Current verdict: look into "autoconfig" keywords: autoadmin, autoconfig.jsc, failover.jsc, MCD, Autoconfig, Mission Control Desktop,

deliciouslytyped commented 5 years ago

Autoconf: After running across the "Mission Control Desktop" keywords here: http://forums.mozillazine.org/viewtopic.php?f=39&t=601199 I finally made some progress figuring this stuff out, which is to say, documentation seems to be extremely spotty unless you assume decade old articles from 55 versions ago are still relevant.

This is the firefox code relating to this "autoconfig" stuff https://dxr.mozilla.org/mozilla-central/source/extensions/pref/autoconfig

https://bugzilla.mozilla.org/show_bug.cgi?id=1438247 After some digging, here seems to be some relatively recent input on Autoconfig / MCD / Mission Control Desktop / ??? being officially supported, and used in large enterprises/whatever. This component seems to have a history, and https://bugzilla.mozilla.org/show_bug.cgi?id=1438247#c16 suggests it probably wont get removed immediately (?), so unless Mozilla unilaterally pulls another Quantum this seems like a viable path to (more) declarative configuration? It also appears to be relevant to all mozilla products.

It needs to be clarified whether the new Windows Group Policy Objects based stuff will be present in parallel to MCD, or whether MCD will be phased out and removed, and we will be left with the (currently?) crippled GPO stuff.

If Autoconfig is a viable option, how stable are the firefox config APIs? Do numeric constants change? (e.g. browser.startup.page uses a numeric constant like an enum)

Bugzillas: (note these dont show closed issues, need to edit the search) https://bugzilla.mozilla.org/buglist.cgi?product=Core&component=AutoConfig%20(Mission%20Control%20Desktop) For bugs using an AutoConfig (mozilla.cfg) file to configure Firefox or other Mozilla applications. NOT for Thunderbird Autoconfiguration. https://bugzilla.mozilla.org/buglist.cgi?quicksearch=mcd

Note: there are mentions of LDAP support, changig these files only has results on next start of firefox (?) TODO: prefs.js vs user.js vs autoconfig.js

deliciouslytyped commented 5 years ago

@wsmwk @mkaply can you shed some light on the above? I would very much appreciate not needing to poke in the dark. :)

I am looking for a way to do per-profile firefox configuration on linux, with tools (here: Nix) externally imposing configuration settings on firefox, say, by adding a generated "autoconfigure" file.

xaverdh commented 5 years ago

A common problem with all of those options appears to be that it tries really hard to resolve configuration files relative to the real executable. That defeats the usual methods for configuration through wrapping. The tor-browser-bundle works around this by copying the entire runtime around. Maybe this can be done for the firefox wrapper as well? Then we could have hooks for {policies.json,...} in the wrapper package.

I am also interested in configuring firefox through nix.

xaverdh commented 5 years ago

Another possible (but rather hacky) solution for this problem is to use user namespaces and bind mounts to work around that. I have a proof of concept script here.

deliciouslytyped commented 5 years ago

@xaverdh I must have forgotten to mention it, but because autoconf is a js file, it might be possible to just have a global autoconfig that lets you set an environment variable to load further configuration from. IIRC the documentation explicitly suggests the possibility of using env vars. Now, I don't know if this is a good idea, but it sounds like it could work well.

In analogy to the emacs stuff I've been working on, you'd have a site-start.el (a "site-specific configuration file run by emacs before the rest of its init process) that calls out to a path set in an environment variable. (also unsure whether that is a good idea, but it works as a first prototype)

xaverdh commented 5 years ago

Ok, my hope is to get some more customizability into the firefox wrapper itself. I opened https://github.com/NixOS/nixpkgs/pull/57554 to get things rolling.

mkaply commented 5 years ago

Thunderbird policies is just not something on our radar right now. As you found, you can use autoconfig to customize thunderbird (Not to be confused with the thunderbird autoconfig server for configuring email servers).

deliciouslytyped commented 5 years ago

Though I guess given how nix in general works, it's probably fine to have config stuff set in the firefox root because we can easily just generate new ones? and I think total rebuilds of firefox / wasting disk space could be avoided by just using symlinkJoin or something like that?

rycee commented 5 years ago

Just want to say that it is very nice of you to put some effort into Firefox configuration. At some point I had a quick look at it but gave up quite quickly 😀 I'll help in what way I can.

For what it's worth, I've added an option programs.firefox.extensions that can be used to declaratively add Firefox extensions. It's not very fancy, simply copies them to the extensions directory where Firefox will see them. Right now the only source of addon packages is from my NUR.

deliciouslytyped commented 5 years ago

Meanwhile I just realized this might be helpful for anything else in this ecosystem like zotero. (?)

deliciouslytyped commented 5 years ago

Some more misc. links: https://firefox-source-docs.mozilla.org/ https://github.com/7c6f434c/lang-os/blob/master/wrapped-firefox-launcher.nix https://github.com/7c6f434c/lang-os/blob/master/firefox-profile.nix

rycee commented 5 years ago

I just merged #719, which adds some profile handling and generation of user.js. Please have a look and see what you think. See https://rycee.gitlab.io/home-manager/options.html#opt-programs.firefox.profiles for the new options.

deliciouslytyped commented 5 years ago

A very rough implementation for generating a string from a nested attribute set in that style:

#nix eval -f attrtostr.nix a
with import <nixpkgs> {};

#Huh, this implementation coincidentally ignores options that are empty sets.
let
  wot = {
    a = {
      b = 1;
      };
    b = 2;
    c = {};
    d = "asd";
    e.f.g = 3;
    };

  dropLeadingDot = s: builtins.substring 1 (builtins.stringLength s) s;

  typeCase = v: ifrec: ifval:
    if (builtins.typeOf v == "set")
      then ifrec
      else ifval;

    ifVal = acc: v: "${acc}=${builtins.toString v}";

  m = acc: a:
    let
      acc' = n: "${acc}.${n}";
    in
      #TODO this is a deprecated function
      lib.mapAttrsFlatten (n: v: typeCase v (m (acc' n) v) (ifVal (acc' n) v)) a;
in {
  a = lib.traceValSeq ("\n" + (lib.concatMapStringsSep "\n" dropLeadingDot (lib.flatten (m "" wot))));
  }
deliciouslytyped commented 4 years ago

Some stuff about profile up- aand down-grades for more recent foxes: https://discourse.nixos.org/t/why-does-the-following-setup-reset-firefox/4129

I didn't really look into it.

mestaritonttu commented 3 years ago

How to import Firefox bookmarks without GUI: https://stackoverflow.com/a/35804955/3057764

nh2 commented 3 years ago

Please have a look and see what you think. See https://rycee.gitlab.io/home-manager/options.html#opt-programs.firefox.profiles for the new options.

@rycee FYI in my current .mozilla/firefox/profiles.ini there is a Version=2:

[General]
StartWithLastProfile=1
Version=2

Your generated ini currently doesn't generate that (https://github.com/nix-community/home-manager/blob/cf5dad76c1ee452224da39f13129c4ff84351a5c/modules/programs/firefox.nix#L47-L49); I'm wondering whether it should. I couldn't find out what concrete difference it makes so far.

deliciouslytyped commented 3 years ago

Lol how about no