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

bug: Firefox no longer launches with custom profiles #5717

Closed
2 tasks done
dairyisscary opened this issue Aug 8, 2024 · 13 comments · Fixed by #5723 · May be fixed by #5801
Closed
2 tasks done

bug: Firefox no longer launches with custom profiles #5717

dairyisscary opened this issue Aug 8, 2024 · 13 comments · Fixed by #5723 · May be fixed by #5801
Assignees
Labels
bug triage Issues or feature request that have not been triaged yet

Comments

@dairyisscary
Copy link

Are you following the right branch?

  • My Nixpkgs and Home Manager versions are in sync

Is there an existing issue for this?

  • I have searched the existing issues

Issue description

I have a home module that looks something like this:

  programs.firefox = {
    enable = true;
    package = lib.mkIf isDarwin (pkgs.firefox-bin.overrideAttrs (prevAttrs: {
      postInstall = ''
        folder="$out/Applications/Firefox.app/Contents/Resources/distribution"
        mkdir -p "$folder"
        echo '{
          "policies": {
            "AppAutoUpdate": false,
            "DisableAppUpdate": true
          }
        }' > "$folder/policies.json"
      '';
    }));
    profiles.${config.home.username} = {
      settings = {
        "toolkit.legacyUserProfileCustomizations.stylesheets" = true;
      };
      userChrome = builtins.readFile ./firefox-userchrome.css;
      search = {
        force = true;
        default = "Kagi";
        engines = {
           # elided...
        };
      };
    };
  };

After #5128, firefox no longer opens on aarch64-darwin (I have not tested any other platform). I have verified that the commit before is not affected.

I noticed that profiles.ini file looks exactly the same between the two profiles, with #5128 and without, except for this notable line:

[General]
StartWithLastProfile=1
Version=2 # <- this one.

[Profile0]
Default=1
IsRelative=1
Name=eric
Path=Profiles/eric

And that seems to be new configuration in #5128. If i just manually link this file to the older profile without this Version line, but keep the newer profile, firefox does seem to open correctly. I can't find any mozilla documentation on this property.

Maintainer CC

No response

System information

nix run nixpkgs#nix-info -- -m
 - system: `"aarch64-darwin"`
 - host os: `Darwin 23.6.0, macOS 14.6.1`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.18.5`
 - nixpkgs: `/nix/store/4cpakzyvfw1rmm9v5i3387x6jd2h1v86-source`
@dairyisscary dairyisscary added bug triage Issues or feature request that have not been triaged yet labels Aug 8, 2024
@khaneliman
Copy link
Contributor

khaneliman commented Aug 9, 2024

Same behavior here.. I saw it immediately after that got merged too. My workaround for the time being has been to create a rw profiles.ini with the same contents after a flake switch... Only happens on my macbook and my linux desktop doesn't experience the same issue.

@brckd
Copy link
Contributor

brckd commented Aug 14, 2024

My bad. I added that property since I observed that it fixed profiles on most other derivarives such as LibreWolf. I couldn't find any docs on it either, so I just hoped it wouldn't affect browsers that use version 1. Am I correct to assume this only breaks stock FF on Darwin?

@dairyisscary
Copy link
Author

My bad. I added that property since I observed that it fixed profiles on most other derivarives such as LibreWolf. I couldn't find any docs on it either, so I just hoped it wouldn't affect browsers that use version 1. Am I correct to assume this only breaks stock FF on Darwin?

I think its only stock Firefox on Darwin, yes. I tried a x86 linux nixos box today, and it worked just fine with the v2 property. For reference, I'm using the overlays provided here for Darwin since nixpkgs doesn't have good Darwin support for Firefox: https://github.com/bandithedoge/nixpkgs-firefox-darwin

@booxter
Copy link

booxter commented Sep 2, 2024

@dairyisscary I suspect firefox-bin is also affected, even for Linux, see: #5724 (comment) I don't have access to a Linux box with nixos to try it out. Can you by chance check it?

@brckd
Copy link
Contributor

brckd commented Sep 2, 2024

Why would firefox-bin be affected if it was never used in the module? Is there any reason to use firefox-bin over firefox or firefox-unwrapped?

@booxter
Copy link

booxter commented Sep 2, 2024

It can be used. I don't know why one would use it though, but that's an official binary from Mozilla. The reason I think it may be affected is that it probably doesn't use MOZ_LEGACY_PROFILES=1, and as per my theory, it means it won't be compatible with profiles.ini of Version=2 ; this version implies [Install] sections are part of the profiles.ini file and no installs.ini "backup" is created.

UPD: now that I looked a bit closer, I no longer thing firefox-bin would be affected either, because it also uses wrapFirefox wrapper that enforces MOZ_LEGACY_PROFILES=1.

@booxter
Copy link

booxter commented Sep 2, 2024

I added that property since I observed that it fixed profiles on most other derivarives such as LibreWolf

@brckd do you have any details as to how LibreWolf failed without Version=2? I'd think since it uses the same code base as Firefox (with minor adjustments that probably don't affect profile loading), it would handle profiles.ini the same way.

@brckd
Copy link
Contributor

brckd commented Sep 3, 2024

I only saw that it was failing and that LibreWolf's own config includes Version = 2. I never dived into the question as to why this happens, but will try to check the logs today.

@dairyisscary
Copy link
Author

@dairyisscary I suspect firefox-bin is also affected, even for Linux, see: #5724 (comment) I don't have access to a Linux box with nixos to try it out. Can you by chance check it?

I did try the pkgs.firefox-bin (both wrapped and unwrapped) from nixpkgs for x86 nixos and they seemed to work for me, even with the version=2 thing.

@booxter
Copy link

booxter commented Sep 3, 2024

I did some more reading of Firefox code yesterday. This is my current thinking. I copied it from a Thunderbird PR. It is referring to Thunderbird, but the same applies to Firefox.


There are two scenarios that seem to work correctly with a read-only profiles.ini (regardless of the platform):

  1. Set MOZ_LEGACY_PROFILES=1 and set Version=2.
  2. Use default (dedicated profiles per installation) and leave the profiles.ini file without Version set. (Which implies v1.)

When (1) is used, no installs.ini is created in Flush (this is a function in the Mozilla engine). Nor the file is loaded when parsing profiles.ini. This is fine because in this mode Thunderbird does not work with per-install configs.

When (2) is used, installs.ini is loaded as a "backup"; and it's dumped to on Flush. So while profiles.ini still cannot be overridden (because it's read-only), Thunderbird can effectively update its per-install profile config.

The package from nixpkgs, thanks to the wrapThunderbird, sets MOZ_LEGACY_PROFILES=1 for the app. This is why (1) works for Linux but not for Darwin.

This PR proposed to switch to (2). But I think this may break nixpkgs Thunderbird. For this to work, nixpkgs would have to switch to "dedicated profiles" (remove MOZ_LEGACY_PROFILES=1 from the wrapper.) I don't think this is going to happen any time soon (probably never unless Mozilla ever rips of "legacy" profile support from its code base.) So I have to rethink the approach here.


I think in the end, we may have to stick to Version=2 here. As to Darwin users, we can help them by setting MOZ_LEGACY_PROFILES=1 in their session variables. (Right now we only instruct them to do so with a warning.)

This can probably be safely done for all platforms, not just Darwin. The nixpkgs packages already pass this variable to the wrapped apps. And it may be helpful in an (unusual) scenario where a Linux, non-NixOS user may use home-manager without nixpkgs package.

booxter added a commit to booxter/home-manager that referenced this issue Sep 3, 2024
This fixes app startup for installations that are not using
`wrapFirefox` (e.g. app from `homebrew`).

These variables are already set for nixpkgs firefox using wrapFirefox
wrapper.

This is most helpful for Darwin users. But it will help with an
(unusual) scenario where Home Manager is used in a non-NixOS environment
with the app managed by another package manager, or installed directly
from Mozilla builds.

Closes: nix-community#5717
@booxter
Copy link

booxter commented Sep 4, 2024

There seems to be a similar, related bug reported earlier here: #3323

@booxter
Copy link

booxter commented Sep 6, 2024

I think I have a solution for the problem that doesn't require a removal of the Version=2 line in the profiles.ini file for Darwin. The solution is two-fold:

  1. Set MOZ_* variables for Firefox and Thunderbird modules to mimic nixpkgs ("legacy") behavior.
  2. Expose sessionVariables to launchd environment (used to start apps from UI).

With these two pieces in place, I was able to enable firefox and thunderbird modules with the unchanged profiles.ini and then run the apps (installed from homebrew) with Mac UI.

Let me know what you think.

@booxter
Copy link

booxter commented Sep 7, 2024

One more comment on the above solution. nix-darwin has a bug where activate-user is not initialized on reboot. So the solution currently requires a manual activation, or an addition of a user launchd service to run the activate-user script, or this patch for nix-darwin.

booxter added a commit to booxter/home-manager that referenced this issue Sep 21, 2024
This fixes app startup for installations that are not using
`wrapFirefox` (e.g. app from `homebrew`).

These variables are already set for nixpkgs firefox using wrapFirefox
wrapper.

This is most helpful for Darwin users. But it will help with an
(unusual) scenario where Home Manager is used in a non-NixOS environment
with the app managed by another package manager, or installed directly
from Mozilla builds.

Closes: nix-community#5717
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment