Desktop Items
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
Desktop items are typically stored within application subdirectories of paths assigned to the XDG_DATA_DIRS environment variable. On NixOS, those files get included in that variable after being copied to an installed package's $out/share/applications directory. This can be achieved by either linking or copying the files in a phase manually, 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"