bandithedoge / nixpkgs-firefox-darwin

Nixpkgs overlay with Firefox binary builds for macOS
52 stars 6 forks source link

Opening firefox on mac m1 fails to start with error #14

Open masonedmison opened 3 months ago

masonedmison commented 3 months ago

Hi,

I'm on a Macbook Pro with a M1 processor. I'm using the overlay provided in this repo in my flake. When I open up the application (e.g. with open ~/.nix-profile/Applications/Firefox.app/Contents/MacOS/firefox), I get the following error:

/nix/store/ar2628mhd949a5i95sbvsn1x4gn941r6-Firefox-128.0.3/Applications/Firefox.app/Contents/MacOS/firefox ; exit;
chruby: unknown Ruby: ruby-3.1.1
edmisml% /nix/store/ar2628mhd949a5i95sbvsn1x4gn941r6-Firefox-128.0.3/Applications/Firefox.app/Contents/MacOS/firefox ; exit;
UNSUPPORTED (log once): POSSIBLE ISSUE: unit 1 GLD_TEXTURE_INDEX_2D is unloadable and bound to sampler type (Float) - using zero texture because texture unloadable

It looks like a ruby dependency is missing.

rhoriguchi commented 2 months ago

Same issue on M3

 > /nix/Store/z8q4zaf5y3b96hywb8rlp0zc0b3vba42-Firefox-129.0/Applications/Firefox.app/Contents/MacOS/firefox
 UNSUPPORTED (log once): POSSIBLE ISSUE: unit 1 GLD_TEXTURE_INDEX_2D is unloadable and bound to sampler type (Float) - using zero texture because texture unloadable
JayRovacsek commented 2 months ago

@masonedmison @rhoriguchi, do you both use nix-darwin's programs.firefox option by chance? A bit of testing recently I seem to have found that it generates a profiles.ini file that looks like the following:

[General]
StartWithLastProfile=1
Version=2

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

When I removed all traces of Firefox (akin to: rm -rf ~/Library/Application\ Support/Firefox) and launched Firefox; it launched correctly via these builds and generated the following profiles.ini file:

[Profile1]
Name=default
IsRelative=1
Path=Profiles/sq26cl1i.default
Default=1

[Install9C25CD3BE4EC07E3]
Default=Profiles/gnhvasys.default-release
Locked=1

[Profile0]
Name=default-release
IsRelative=1
Path=Profiles/gnhvasys.default-release

[General]
StartWithLastProfile=1
Version=2

Which led me to probe at the existence of the [InstallXXXX] attribute; failing to understand how to correctly identify the Firefox code that handles this, I simply tested lib.mkForce on the generated home.file attribute (ref) that is as below:

home.file."Library/Application Support/Firefox/profiles.ini" = let 
    profiles = lib.flip lib.mapAttrs' cfg.profiles (_: profile:
    lib.nameValuePair "Profile${toString profile.id}" {
      Name = profile.name;
      Path = if pkgs.stdenv.isDarwin then "Profiles/${profile.path}" else profile.path;
      IsRelative = 1;
      Default = if profile.isDefault then 1 else 0;
    }) // {
      General = { StartWithLastProfile = 1; };
    };

  profile-ini = lib.generators.toINI { } profiles;
  in 
  {
    enable = true;
    text = lib.mkForce profile-ini;
  };

edit: the below code suggestion is incorrect - the issue seems to stem from the version property

After which the application seems to launch correctly. In TLDR, does the following addition to profile.ini change your current experience (where foo is your profile name?:

[Install]
Default=Profiles/foo
Locked=1
JayRovacsek commented 2 months ago

Ah! Related: https://github.com/nix-community/home-manager/issues/5717

edit; yep! The above seems to be my cause also

rhoriguchi commented 2 months ago

Yes, I'm using nix-darwin but I'm running the same config on my Linux machine with no issue. So I think the linked issue is the culprit @JayRovacsek

calops commented 2 months ago

https://github.com/nix-community/home-manager/issues/5717#issuecomment-2326444431

Quick workaround is to set MOZ_LEGACY_PROFILES=1. This could easily be done in this flake in a wrapper, until it's fixed upstream.

JayRovacsek commented 2 months ago

nix-community/home-manager#5717 (comment)

Quick workaround is to set MOZ_LEGACY_PROFILES=1. This could easily be done in this flake in a wrapper, until it's fixed upstream.

Ah, this is a really neat way compared to what I'd suggested above, thanks!

calops commented 1 month ago

Alright, so, on my system I can launch firefox like this:

MOZ_LEGACY_PROFILES=1 ~/Applications/Home\ Manager\ Apps/Firefox.app/Contents/MacOS/firefox

And it works as expected. However, I've tried to do it in a more streamlined way in my config:

pkgs.firefox-beta-bin.overrideAttrs {
  nativeBuildInputs = [ pkgs.makeBinaryWrapper ];
  postInstall = ''
    wrapProgram $out/Applications/Firefox.app/Contents/MacOS/firefox --set MOZ_LEGACY_PROFILES 1
  '';
}

This produces the correct wrapper, however... it automatically sends a SIGKILL to the program whenever we try to run it. I imagine it's MacOS killing it automatically because of the program's signature being different, or something like that? Which makes sense, but I don't see any workaround for this.