2021-06-02 23:36:17 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
desktopEntry = {
|
|
|
|
options = {
|
|
|
|
# Since this module uses the nixpkgs/pkgs/build-support/make-desktopitem function,
|
|
|
|
# our options and defaults follow its parameters, with the following exceptions:
|
|
|
|
|
|
|
|
# `desktopName` on makeDesktopItem is controlled by `name`.
|
|
|
|
# This is what we'd commonly consider the name of the application.
|
|
|
|
# `name` on makeDesktopItem is controlled by this module's key in the attrset.
|
|
|
|
# This is the file's filename excluding ".desktop".
|
|
|
|
|
|
|
|
# `extraEntries` on makeDesktopItem is controlled by `extraConfig`,
|
|
|
|
# and `extraDesktopEntries` by `settings`,
|
|
|
|
# to match what's commonly used by other home manager modules.
|
|
|
|
|
|
|
|
# `mimeType` and `categories` on makeDesktopItem ask for a string in the format "one;two;three;",
|
2022-01-05 03:58:20 +00:00
|
|
|
# for usability's sake we ask for a list of strings.
|
2021-06-02 23:36:17 +00:00
|
|
|
|
|
|
|
# Descriptions are taken from the desktop entry spec:
|
|
|
|
# https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#recognized-keys
|
|
|
|
|
|
|
|
type = mkOption {
|
|
|
|
description = "The type of the desktop entry.";
|
|
|
|
default = "Application";
|
|
|
|
type = types.enum [ "Application" "Link" "Directory" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
exec = mkOption {
|
|
|
|
description = "Program to execute, possibly with arguments.";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
icon = mkOption {
|
|
|
|
description = "Icon to display in file manager, menus, etc.";
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
comment = mkOption {
|
|
|
|
description = "Tooltip for the entry.";
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
terminal = mkOption {
|
|
|
|
description = "Whether the program runs in a terminal window.";
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
description = "Specific name of the application.";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
genericName = mkOption {
|
|
|
|
description = "Generic name of the application.";
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
mimeType = mkOption {
|
|
|
|
description = "The MIME type(s) supported by this application.";
|
|
|
|
type = types.nullOr (types.listOf types.str);
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
categories = mkOption {
|
|
|
|
description =
|
|
|
|
"Categories in which the entry should be shown in a menu.";
|
|
|
|
type = types.nullOr (types.listOf types.str);
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
startupNotify = mkOption {
|
|
|
|
description = ''
|
|
|
|
If true, it is KNOWN that the application will send a "remove"
|
|
|
|
message when started with the <literal>DESKTOP_STARTUP_ID</literal>
|
|
|
|
environment variable set. If false, it is KNOWN that the application
|
|
|
|
does not work with startup notification at all.'';
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
2022-01-05 03:58:20 +00:00
|
|
|
noDisplay = mkOption {
|
|
|
|
description = ''
|
|
|
|
Means "this application exists, but don't display it in the menus".
|
|
|
|
This can be useful to e.g. associate this application with MIME types.
|
|
|
|
'';
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
prefersNonDefaultGPU = mkOption {
|
|
|
|
description = ''
|
|
|
|
If true, the application prefers to be run on a more powerful discrete GPU if available.
|
|
|
|
'';
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
2021-06-02 23:36:17 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
description = ''
|
|
|
|
Extra configuration. Will be appended to the end of the file and
|
|
|
|
may thus contain extra sections.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = types.attrsOf types.string;
|
|
|
|
description = ''
|
|
|
|
Extra key-value pairs to add to the <literal>[Desktop Entry]</literal> section.
|
|
|
|
This may override other values.
|
|
|
|
'';
|
|
|
|
default = { };
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''
|
2021-06-02 23:36:17 +00:00
|
|
|
{
|
|
|
|
Keywords = "calc;math";
|
|
|
|
DBusActivatable = "false";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
fileValidation = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = "Whether to validate the generated desktop file.";
|
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
#formatting helpers
|
|
|
|
ifNotNull = a: a': if a == null then null else a';
|
|
|
|
semicolonList = list:
|
|
|
|
(concatStringsSep ";" list) + ";"; # requires trailing semicolon
|
|
|
|
|
|
|
|
#passes config options to makeDesktopItem in expected format
|
|
|
|
makeFile = name: config:
|
|
|
|
pkgs.makeDesktopItem {
|
2022-01-05 03:58:20 +00:00
|
|
|
inherit name;
|
|
|
|
inherit (config)
|
|
|
|
type exec icon comment terminal genericName startupNotify noDisplay
|
|
|
|
prefersNonDefaultGPU;
|
2021-06-02 23:36:17 +00:00
|
|
|
desktopName = config.name;
|
|
|
|
mimeType = ifNotNull config.mimeType (semicolonList config.mimeType);
|
|
|
|
categories =
|
|
|
|
ifNotNull config.categories (semicolonList config.categories);
|
|
|
|
extraEntries = config.extraConfig;
|
|
|
|
extraDesktopEntries = config.settings;
|
|
|
|
};
|
|
|
|
in {
|
2021-12-25 18:19:45 +00:00
|
|
|
meta.maintainers = [ hm.maintainers.cwyc ];
|
2021-06-02 23:36:17 +00:00
|
|
|
|
|
|
|
options.xdg.desktopEntries = mkOption {
|
|
|
|
description = ''
|
|
|
|
Desktop Entries allow applications to be shown in your desktop environment's app launcher. </para><para>
|
|
|
|
You can define entries for programs without entries or override existing entries. </para><para>
|
|
|
|
See <link xlink:href="https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#recognized-keys" /> for more information on options.
|
|
|
|
'';
|
|
|
|
default = { };
|
|
|
|
type = types.attrsOf (types.submodule desktopEntry);
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''
|
2021-06-02 23:36:17 +00:00
|
|
|
{
|
|
|
|
firefox = {
|
|
|
|
name = "Firefox";
|
|
|
|
genericName = "Web Browser";
|
|
|
|
exec = "firefox %U";
|
|
|
|
terminal = false;
|
|
|
|
categories = [ "Application" "Network" "WebBrowser" ];
|
|
|
|
mimeType = [ "text/html" "text/xml" ];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-07-07 21:24:27 +00:00
|
|
|
config = mkIf (config.xdg.desktopEntries != { }) {
|
|
|
|
assertions = [
|
|
|
|
(hm.assertions.assertPlatform "xdg.desktopEntries" pkgs platforms.linux)
|
|
|
|
];
|
|
|
|
|
|
|
|
home.packages = (map hiPrio # we need hiPrio to override existing entries
|
2021-06-02 23:36:17 +00:00
|
|
|
(attrsets.mapAttrsToList makeFile config.xdg.desktopEntries));
|
2021-07-07 21:24:27 +00:00
|
|
|
};
|
2021-06-02 23:36:17 +00:00
|
|
|
|
|
|
|
}
|