9

I am using NixOS with Gnome, and would like to set Chromium as the default browser.

The 'Details' section of my settings, under 'default applications' shows the following:

enter image description here

Both Chromium and Firefox have been installed on my system (Chromium via $ nix-env -i chromium), and yet they do not show up under the drop-down for 'Web', which shows only the one option.

How can I set Chromium to be my default browser?

4 Answers 4

7

For Apps Following the XDG Spec

As of NixOS 21.11 or later, one may now set xdg.mime.defaultApplications. For example, to make Qutebrowser the default web browser:

xdg.mime.defaultApplications = {
  "text/html" = "org.qutebrowser.qutebrowser.desktop";
  "x-scheme-handler/http" = "org.qutebrowser.qutebrowser.desktop";
  "x-scheme-handler/https" = "org.qutebrowser.qutebrowser.desktop";
  "x-scheme-handler/about" = "org.qutebrowser.qutebrowser.desktop";
  "x-scheme-handler/unknown" = "org.qutebrowser.qutebrowser.desktop";
}

Ensure xdg.mime.enable is true, which is the default, or the above snippet will have no effect.

For Electron apps:

Electron based desktop applications seem to pull their default browser instance for opening links from the DEFAULT_BROWSER environmental variable. Which expects to be set to either a binary which can be found in the PATH, or a full path to the binary to use.

Another example, again setting qutebrowser:

environment.sessionVariables.DEFAULT_BROWSER = "${pkgs.qutebrowser}/bin/qutebrowser"
6

NixOS does not manage user-specific configuration. Full-stop.

As for the browsers not being found by the configuration dialog, try installing them via /etc/nixos/configuration.nix instead of with nix-env.

Tip

If you install packages declaratively and imperatively you'll end up having to manage two dependency trees. One via nixos-rebuild --upgrade boot and another by nix-channel --update && nix-env -u. Meaning that if you forget either update process you'll end up with old packages installed.

5

For Home Manager:

The system-wide settings on nrdxp's answer may be ignored for one reason or another, so if it doesn't work and you're using Home Manager, try setting them per-user. To do that, you need to replace mime with mimeApps and set enable = true, since it's disabled by default. Adapting their snippet we get:

home-manager.users.<YOUR_USER_NAME>.xdg.mimeApps = {
  enable = true;
  
  defaultApplications = {
    "text/html" = "org.qutebrowser.qutebrowser.desktop";
    "x-scheme-handler/http" = "org.qutebrowser.qutebrowser.desktop";
    "x-scheme-handler/https" = "org.qutebrowser.qutebrowser.desktop";
    "x-scheme-handler/about" = "org.qutebrowser.qutebrowser.desktop";
    "x-scheme-handler/unknown" = "org.qutebrowser.qutebrowser.desktop";
  };
};

You need to do this with every user you want this configured for.

2

There is a typo in @nrdxp's answer an s too much in sessionsVariables. It should be: Unfortunately I don't have enough reputation to comment.

environment.sessionVariables.DEFAULT_BROWSER = "${pkgs.qutebrowser}/bin/qutebrowser"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .