2021-06-03 01:36:17 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
desktopEntry = {
|
2022-03-02 15:01:40 +01:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "extraConfig" ]
|
|
|
|
"The `extraConfig` option of `xdg.desktopEntries` has been removed following a change in Nixpkgs.")
|
2022-04-18 00:06:09 +02:00
|
|
|
(mkRemovedOptionModule [ "fileValidation" ]
|
|
|
|
"Validation of the desktop file is always enabled.")
|
2022-03-02 15:01:40 +01:00
|
|
|
];
|
2021-06-03 01:36:17 +02:00
|
|
|
options = {
|
2022-03-02 15:01:40 +01:00
|
|
|
# Since this module uses the nixpkgs/pkgs/build-support/make-desktopitem function,
|
2021-06-03 01:36:17 +02:00
|
|
|
# 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".
|
|
|
|
|
2022-03-02 15:01:40 +01:00
|
|
|
# `extraConfig` on makeDesktopItem is controlled by `settings`,
|
2021-06-03 01:36:17 +02:00
|
|
|
# to match what's commonly used by other home manager modules.
|
|
|
|
|
2022-03-02 15:01:40 +01:00
|
|
|
# Descriptions are taken from the desktop entry spec:
|
2021-06-03 01:36:17 +02:00
|
|
|
# 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.";
|
2022-03-02 15:01:40 +01:00
|
|
|
type = types.nullOr types.str;
|
2021-06-03 01:36:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
icon = mkOption {
|
|
|
|
description = "Icon to display in file manager, menus, etc.";
|
2022-07-10 08:17:37 +02:00
|
|
|
type = with types; nullOr (either str path);
|
2021-06-03 01:36:17 +02:00
|
|
|
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 = ''
|
2022-03-02 15:01:40 +01:00
|
|
|
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
|
2021-06-03 01:36:17 +02:00
|
|
|
does not work with startup notification at all.'';
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
2022-01-05 04:58:20 +01: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-03 01:36:17 +02:00
|
|
|
settings = mkOption {
|
|
|
|
type = types.attrsOf types.string;
|
|
|
|
description = ''
|
2022-03-02 15:01:40 +01:00
|
|
|
Extra key-value pairs to add to the <literal>[Desktop Entry]</literal> section.
|
2021-06-03 01:36:17 +02:00
|
|
|
This may override other values.
|
|
|
|
'';
|
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2021-06-03 01:36:17 +02:00
|
|
|
{
|
|
|
|
Keywords = "calc;math";
|
|
|
|
DBusActivatable = "false";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-04-18 00:06:09 +02:00
|
|
|
actions = mkOption {
|
|
|
|
type = types.attrsOf (types.submodule ({ name, ... }: {
|
|
|
|
options.name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = name;
|
|
|
|
defaultText = literalExpression "<name>";
|
|
|
|
description = "Name of the action.";
|
|
|
|
};
|
|
|
|
options.exec = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
description = "Program to execute, possibly with arguments.";
|
|
|
|
};
|
|
|
|
options.icon = mkOption {
|
2022-07-10 08:17:37 +02:00
|
|
|
type = with types; nullOr (either str path);
|
2022-04-18 00:06:09 +02:00
|
|
|
default = null;
|
|
|
|
description = "Icon to display in file manager, menus, etc.";
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
default = { };
|
|
|
|
defaultText = literalExpression "{ }";
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
"New Window" = {
|
|
|
|
exec = "''${pkgs.firefox}/bin/firefox --new-window %u";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description =
|
|
|
|
"The set of actions made available to application launchers.";
|
2021-06-03 01:36:17 +02:00
|
|
|
};
|
2022-03-02 15:01:40 +01:00
|
|
|
|
|
|
|
# Required for the assertions
|
2022-06-07 20:45:06 +02:00
|
|
|
# TODO: Remove me once https://github.com/NixOS/nixpkgs/issues/96006 is fixed
|
2022-03-02 15:01:40 +01:00
|
|
|
assertions = mkOption {
|
|
|
|
type = types.listOf types.unspecified;
|
|
|
|
default = [ ];
|
|
|
|
visible = false;
|
|
|
|
internal = true;
|
|
|
|
};
|
2021-06-03 01:36:17 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
#formatting helpers
|
|
|
|
semicolonList = list:
|
|
|
|
(concatStringsSep ";" list) + ";"; # requires trailing semicolon
|
|
|
|
|
|
|
|
#passes config options to makeDesktopItem in expected format
|
|
|
|
makeFile = name: config:
|
|
|
|
pkgs.makeDesktopItem {
|
2022-01-05 04:58:20 +01:00
|
|
|
inherit name;
|
|
|
|
inherit (config)
|
|
|
|
type exec icon comment terminal genericName startupNotify noDisplay
|
2022-04-18 00:06:09 +02:00
|
|
|
prefersNonDefaultGPU actions;
|
2021-06-03 01:36:17 +02:00
|
|
|
desktopName = config.name;
|
2022-03-02 15:01:40 +01:00
|
|
|
mimeTypes = optionals (config.mimeType != null) config.mimeType;
|
|
|
|
categories = optionals (config.categories != null) config.categories;
|
|
|
|
extraConfig = config.settings;
|
2021-06-03 01:36:17 +02:00
|
|
|
};
|
|
|
|
in {
|
2021-12-25 19:19:45 +01:00
|
|
|
meta.maintainers = [ hm.maintainers.cwyc ];
|
2021-06-03 01:36:17 +02: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 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2021-06-03 01:36:17 +02:00
|
|
|
{
|
|
|
|
firefox = {
|
|
|
|
name = "Firefox";
|
|
|
|
genericName = "Web Browser";
|
|
|
|
exec = "firefox %U";
|
|
|
|
terminal = false;
|
|
|
|
categories = [ "Application" "Network" "WebBrowser" ];
|
|
|
|
mimeType = [ "text/html" "text/xml" ];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-07-07 23:24:27 +02:00
|
|
|
config = mkIf (config.xdg.desktopEntries != { }) {
|
|
|
|
assertions = [
|
|
|
|
(hm.assertions.assertPlatform "xdg.desktopEntries" pkgs platforms.linux)
|
2022-03-02 15:01:40 +01:00
|
|
|
] ++ flatten (catAttrs "assertions" (attrValues config.xdg.desktopEntries));
|
2021-07-07 23:24:27 +02:00
|
|
|
|
|
|
|
home.packages = (map hiPrio # we need hiPrio to override existing entries
|
2021-06-03 01:36:17 +02:00
|
|
|
(attrsets.mapAttrsToList makeFile config.xdg.desktopEntries));
|
2021-07-07 23:24:27 +02:00
|
|
|
};
|
2021-06-03 01:36:17 +02:00
|
|
|
|
|
|
|
}
|