Jump to content

Default applications: Difference between revisions

From NixOS Wiki
Onny (talk | contribs)
Initial page
 
34j (talk | contribs)
Note the way to list all .desktop-files
(One intermediate revision by one other user not shown)
Line 15: Line 15:
   };
   };
};
};
</syntaxhighlight>In case a program is missing a .desktop-file, the following example adds a <code>librewolf.desktop</code> file to the MIME database with the specific binary path.<syntaxhighlight lang="nix">
</syntaxhighlight>
 
To list all .desktop-files, run
 
<pre>
ls /run/current-system/sw/share/applications # for global packages
ls ~/.nix-profile/share/applications # for home-manager packages
</pre>
 
In case a program is missing a .desktop-file, the following example adds a <code>librewolf.desktop</code> file to the MIME database with the specific binary path.<syntaxhighlight lang="nix">
home-manager.users.myuser = {
home-manager.users.myuser = {
   xdg.desktopEntries.librewolf = {
   xdg.desktopEntries.librewolf = {
Line 28: Line 37:
xdg-open "https://nixos.org"
xdg-open "https://nixos.org"
</syntaxhighlight>
</syntaxhighlight>
[[Category:Home Manager]]

Revision as of 07:22, 10 February 2025

Different programs manage default application associations in unique ways. Command-line applications often use environment variables, whereas graphical applications typically utilize XDG MIME applications via APIs like GIO or Qt, or by calling xdg-open.

Configuration

Using Home Manager, this configuration example configures the handling of HTML-files and URLs by opening them with the browser LibreWolf. Replace myuser with the name of your low-level user.

home-manager.users.myuser = {
  xdg.mimeApps = {
    enable = true;
    defaultApplications = {
      "text/html" = "librewolf.desktop";
      "x-scheme-handler/http" = "librewolf.desktop";
      "x-scheme-handler/https" = "librewolf.desktop";
      "x-scheme-handler/about" = "librewolf.desktop";
      "x-scheme-handler/unknown" = "librewolf.desktop";
    };
  };
};

To list all .desktop-files, run

ls /run/current-system/sw/share/applications # for global packages
ls ~/.nix-profile/share/applications # for home-manager packages

In case a program is missing a .desktop-file, the following example adds a librewolf.desktop file to the MIME database with the specific binary path.

home-manager.users.myuser = {
  xdg.desktopEntries.librewolf = {
    name = "LibreWolf";
    exec = "${pkgs.librewolf}/bin/librewolf";
  };
};

Usage

Try opening a web page with xdg-open which is part of the package xdg-utils

xdg-open "https://nixos.org"