How to use overlays in Home Manager to install Firefox?

OS: macOS, 10.15.7 (Catalina)
Nix: 2.12.0
Home-Manager: 22.11

The followng appears to be a very newb syntax error on my part that I cannot fix. Prior to this, I was getting an error that stated something like: expected a set but got a thunk in regards to the nipkgs.overlays block in the following flake.nix. In my attempt to fix that, I’m now stuck at the current newb error:

error: syntax error, unexpected '='

       at /nix/store/8fs94g915ncpa7486ysvhyaca34j25a8-source/flake.nix:36:42:

           35|           })
           36|             programs.home-manager.enable = true;
             |                                          ^
           37|             programs.helix.enable = true;

My Home Manager flake
~/.config/nixpkgs/flake.nix:

{
  description = "Home Manager configuration of me";

  inputs = {
    # Specify overlays.
    nur = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz");
    moz_overlay = import (builtins.fetchTarball "https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz");
    nixpkgs = {
                url = "github:nixos/nixpkgs/nixos-unstable";
              };
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { nur, moz_overlay, nixpkgs, home-manager, ... }:
    let
      username = "me";
      system = "x86_64-darwin";
    in {
      homeConfigurations.${username} = home-managr.lib.homeManagerConfiguration {
        pkgs = ixpkgs.legacyPackags.${system};
        modules = [
          ({
            nipkgs.overlays = [
                                nur.overlay
                                moz_overlay
                               ];
            home = {
              inherit username;
              homeDirectory = "/Users/${username}";
              stateVersion = "22.11";
            };
          })
            programs.home-manager.enable = true;
            programs.helix.enable = true;
            programs.htop.enable = true;
            programs.lazygit.enable = true;
            programs.lsd.enable = true;
            programs.jq.enable = true;
            programs.alacritty.enable = true;
            programs.skim.enable = true;
            ./home_manager/modules/cli/fzf.nix
            ./home_manager/modules/cli/git.nix
            ./home_manager/modules/gui/blender.nix
            ./home_manager/modules/gui/libreoffice.nix
            ./home_manager/modules/gui/iina.nix
    ];
  };
}

The firefox nix file I copied from someone’s github repo that may work or not for me
~/.config/nixpkgs/home_manager/modules/gui/firefox.nix:

{ config, pkgs, theme, ... }:

{
    programs.firefox = {
        enable = true;
        package = pkgs.wrapFirefox pkgs.firefox-unwrapped {
            extraPolicies = {
                CaptivePortal = false;
                DisableFirefoxStudies = true;
                DisablePocket = true;
                NoDefaultBookmarks = true;
                OfferToSaveLogins = true;
                OfferToSaveLoginsDefault = false;
                PasswordManagerEnabled = true;
                FirefoxHome = {
                    Search = true;
                    Pocket = false;
                    Snippets = false;
                    TopSites = false;
                    Highlights = false;
                };
                UserMessaging = {
                };
            };
        };
        extensions = with pkgs.nur.repos.rycee.firefox-addons; [
            noscript
            ublock-origin
            privacy-badger
            clearurls
            decentraleyes
        ];
        profiles = {
            me = {
                id = 0;
                name = "me";
                search = {
                    force = true;
                    default = "DuckDuckGo";
                    engines = {
                        "Nix Packages" = {
                            urls = [{
                                template = "https://search.nixos.org/packages";
                                params = [
                                    { name = "type"; value = "packages"; }
                                    { name = "query"; value = "{searchTerms}"; }
                                ];
                            }];
                            icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg";
                            definedAliases = [ "@np" ];
                        };
                        "Google".metaData.hidden = true;
                        "Amazon.com".metaData.hidden = true;
                        "Bing".metaData.hidden = true;
                        "eBay".metaData.hidden = true;
                    };
                };
                settings = {
                    "general.smoothScroll" = true;
                };
            };
        };
    };
}

I took the freedom to simply fix your flake.nix:

{
  description = "Home Manager configuration of me";

  inputs = {
    # Specify overlays. - not really what you're doing, these are just inputs, the overlay specification is down in your inline module
    nur.url = "github:nix-community/NUR";
    moz_overlay.url = "github:mozilla/nixpkgs-mozilla";
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { nur, moz_overlay, nixpkgs, home-manager }: let
    username = "me";
    system = "x86_64-darwin";
  in {
    homeConfigurations.${username} = home-manager.lib.homeManagerConfiguration {
      pkgs = nixpkgs.legacyPackags.${system};
      modules = [
        ({
          nipkgs.overlays = [
            nur.overlay
            moz_overlay
          ];

          home = {
            inherit username;
            homeDirectory = "/Users/${username}";
            stateVersion = "22.11";
          };

          programs.home-manager.enable = true;
          programs.helix.enable = true;
          programs.htop.enable = true;
          programs.lazygit.enable = true;
          programs.lsd.enable = true;
          programs.jq.enable = true;
          programs.alacritty.enable = true;
          programs.skim.enable = true;
        })

        ./home_manager/modules/cli/fzf.nix
        ./home_manager/modules/cli/git.nix
        ./home_manager/modules/gui/blender.nix
        ./home_manager/modules/gui/libreoffice.nix
        ./home_manager/modules/gui/iina.nix
      ];
    };
  };
}

A few things went wrong:

  1. Flake inputs should never use fetchurl. The point is that nix resolves those without language features, so that you can manage reproducible references with the nix CLI instead. I’ve fixed that.
  2. You defined an inline module in the ({}) bit. Modules are the only place where you can assign values to options. You then closed the module, and started assigning things to options in an array, which makes no sense. I’ve pit those option declarations in the inline module instead, and left the file path references outside, where they belong.
  1. The formatting was screwy and you were missing a closing bracket. Presumably that was a typo because you hand-typed the flake.nix instead of copying it? Either way, being consistent with formatting helps spotting missing brackets, so I would recommend it.

As for the firefox thing; it looks fine, you’re not currently importing it though.

2 Likes

Thanks @TLATER, your explanation is as always awesome and better than most tutorials I have tried to understand!

LOL, I edited out a few paths to other nix files to keep my flake easier to read here and accidentally deleted the firefox.nix file, which I’ve included now.

With and without that file, I’m now getting this error:

error: 'outputs' at /nix/store/nwv54b8w6bw7dkcmkan88vlkw50kw24j-source/flake.nix:15:13 called with unexpected argument 'self'

       at «string»:45:21:

           44|
           45|           outputs = flake.outputs (inputs // { self = result; });
             |                     ^
           46|

Ah, whoops, my bad. Forgot self was an implicit input for a second, I broke that by changing:

To:

The ellipsis allows arbitrary arguments to be passed and ignored. By removing it, the self input you correctly ignored is causing issues. Just put the ellipsis back, sorry for the confusion!

The self input is used to refer to the flake itself, by the way. That way you can do things like refer to self.homeConfigurations.me (far more useful if you define packages or lib). Or even to specific files in your flake, you can e.g. get the path to your flake.nix with "${self}/flake.nix". Can be handy from time to time.

1 Like

Thanks @TLATER!!

That appears to work, because I get this error:

error: flake 'git+file:///Users/me/.config/nixpkgs' does not provide attribute 'packages.x86_64-darwin.homeConfigurations."me".activationPackage', 'legacyPackages.x86_64-darwin.homeConfigurations."me".activationPackage' or 'homeConfigurations."me".activationPackage'

which I guess confirms that there is no package for firefox for x86_64-darwin.

I saw this when I tried to install firefox via programs.firefox.enable in home manager, but hoped by using the overlay, there may be a version of firefox (eg a nightly) that I could use.

If the above error does confirm the lack of availbility of firefox for my platform - even with an overlay and via NUR, then I guess I’ll have to wait to use it until I switch to an M chip Mac?

The error is not about Firefox, it says that there is no homeConfigurations.me.

1 Like

Thanks @NobbZ!!

I swap out my real name with ‘me’ for posts here, and forgot after copying TLATER’s fixes (it’s been a long week).

Now I’m getting this…

error: A definition for option `nixpkgs.overlays."[definition 1-entry 2]"' is not of type `nixpkgs overlay'. Definition values:
       - In `<unknown-file>':
           {
             _type = "flake";
             inputs = { };
             lastModified = 1675354105;
             lastModifiedDate = "20230202160825";
           ...
(use '--show-trace' to show detailed location information)

I’ve tried home-manager switch --show-trace - if that’s what the error was advising, and got a long list of nix’s core lib files(?) and not one file of mine to debug.

Because it should probably be moz_overlay.overlay or moz_overlay.overlays.default depending on how exactly the mozilla overlay defines their outputs.

1 Like

Thanks @NobbZ!!

moz_overlay.overlay got everything working - enough to get…

error: Package ‘firefox-109.0’ in /nix/store/ismzj4bksv54y4x2b9spfvk9mqhbcwf8-source/pkgs/applications/networking/browsers/firefox/wrapper.nix:404 is not supported on ‘x86_64-darwin’, refusing to evaluate.

I know Apple’s new chips are popular, but I’m surprised firefox isn’t available via nix for their Intel ones considering the number of developers still using them. I’ll save this config for when I’ve upgraded to a new mac to use firefox via nix on it.

Thanks to you and @TLATER for getting me this far!

2 Likes