Jump to content

Desktop Items

From Official NixOS Wiki

Desktop items (more commonly referred to as "desktop entries") are special files used to provide information to application launchers regarding specific programs, directories, or URLs, which they are meant to handle. As a universal standard, these files should to adhere to their freedesktop.org specification.

Packaging

Creating desktop items

If provided upstream, desktop item files can be copied over to a package's output directly. Alternatively, they may also be generated by using the makeDesktopItem builder:

makeDesktopItem {
  name = "Example Program";
  exec = "example-program";
  categories = [ "Education" ];
}

Copying desktop items

The environment variable XDG_DATA_DIRS can be read by application launchers in search of desktop files. More specifically, it lists paths which may contain applications directories that store them. On NixOS, once a package is installed, its desktop items become discoverable by that variable so long as they are placed in the package output's $out/share/applications directory. This can be achieved by either linking or copying the files there, during an installation phase, or by using the copyDesktopItems hook:

# The hook reads items from this variable.
desktopItems = [
  (makeDesktopItem {
    name = "Example Program";
    exec = "example-program";
    categories = [ "Education" ];
  })
  # ...
];

nativeBuildInputs = [
  copyDesktopItems
];

Tips and Tricks

Validating desktop items

To quickly validate an existing desktop item, the following command may be run:

$ nix-shell -p buildPackages.desktop-file-utils --run "desktop-file-validate ./path/to/file.desktop"