Desktop Items: Difference between revisions
Created an article about Desktop Items |
m Rewrote a paragraph to be more comprehensible |
||
| Line 17: | Line 17: | ||
====Copying desktop items==== | ====Copying desktop items==== | ||
The environment variable <code>XDG_DATA_DIRS</code> can be read by application launchers in search of desktop files. More specifically, it lists paths which may contain <code>applications</code> 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 <code>$out/share/applications</code> directory. This can be achieved by either linking or copying the files there, during an installation [[Derivations#Phases|phase]], or by using the [https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/setup-hooks/copy-desktop-items.sh copyDesktopItems] hook: | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
Latest revision as of 21:46, 3 June 2026
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"