xdg-desktop-entries: adjust to API changes

The `makeDesktopItem` function changed in a backwards incompatible way
in

    0c713dbed4

This commit updates the module accordingly.

Fixes #2767
This commit is contained in:
Sebastian Sellmeier 2022-03-02 15:01:40 +01:00 committed by Robert Helgesson
parent ea85f4b1fd
commit e58a7cb13d
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
4 changed files with 36 additions and 33 deletions

View file

@ -4,8 +4,12 @@ with lib;
let let
desktopEntry = { desktopEntry = {
imports = [
(mkRemovedOptionModule [ "extraConfig" ]
"The `extraConfig` option of `xdg.desktopEntries` has been removed following a change in Nixpkgs.")
];
options = { options = {
# Since this module uses the nixpkgs/pkgs/build-support/make-desktopitem function, # Since this module uses the nixpkgs/pkgs/build-support/make-desktopitem function,
# our options and defaults follow its parameters, with the following exceptions: # our options and defaults follow its parameters, with the following exceptions:
# `desktopName` on makeDesktopItem is controlled by `name`. # `desktopName` on makeDesktopItem is controlled by `name`.
@ -13,14 +17,10 @@ let
# `name` on makeDesktopItem is controlled by this module's key in the attrset. # `name` on makeDesktopItem is controlled by this module's key in the attrset.
# This is the file's filename excluding ".desktop". # This is the file's filename excluding ".desktop".
# `extraEntries` on makeDesktopItem is controlled by `extraConfig`, # `extraConfig` on makeDesktopItem is controlled by `settings`,
# and `extraDesktopEntries` by `settings`,
# to match what's commonly used by other home manager modules. # 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;", # Descriptions are taken from the desktop entry spec:
# for usability's sake we ask for a list of strings.
# Descriptions are taken from the desktop entry spec:
# https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#recognized-keys # https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#recognized-keys
type = mkOption { type = mkOption {
@ -31,7 +31,7 @@ let
exec = mkOption { exec = mkOption {
description = "Program to execute, possibly with arguments."; description = "Program to execute, possibly with arguments.";
type = types.str; type = types.nullOr types.str;
}; };
icon = mkOption { icon = mkOption {
@ -78,9 +78,9 @@ let
startupNotify = mkOption { startupNotify = mkOption {
description = '' description = ''
If true, it is KNOWN that the application will send a "remove" If true, it is KNOWN that the application will send a "remove"
message when started with the <literal>DESKTOP_STARTUP_ID</literal> message when started with the <literal>DESKTOP_STARTUP_ID</literal>
environment variable set. If false, it is KNOWN that the application environment variable set. If false, it is KNOWN that the application
does not work with startup notification at all.''; does not work with startup notification at all.'';
type = types.nullOr types.bool; type = types.nullOr types.bool;
default = null; default = null;
@ -103,19 +103,10 @@ let
default = null; default = null;
}; };
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 { settings = mkOption {
type = types.attrsOf types.string; type = types.attrsOf types.string;
description = '' description = ''
Extra key-value pairs to add to the <literal>[Desktop Entry]</literal> section. Extra key-value pairs to add to the <literal>[Desktop Entry]</literal> section.
This may override other values. This may override other values.
''; '';
default = { }; default = { };
@ -132,11 +123,19 @@ let
description = "Whether to validate the generated desktop file."; description = "Whether to validate the generated desktop file.";
default = true; default = true;
}; };
# Required for the assertions
# TODO: Remove me once `mkRemovedOptionModule` works correctly with submodules
assertions = mkOption {
type = types.listOf types.unspecified;
default = [ ];
visible = false;
internal = true;
};
}; };
}; };
#formatting helpers #formatting helpers
ifNotNull = a: a': if a == null then null else a';
semicolonList = list: semicolonList = list:
(concatStringsSep ";" list) + ";"; # requires trailing semicolon (concatStringsSep ";" list) + ";"; # requires trailing semicolon
@ -148,11 +147,9 @@ let
type exec icon comment terminal genericName startupNotify noDisplay type exec icon comment terminal genericName startupNotify noDisplay
prefersNonDefaultGPU; prefersNonDefaultGPU;
desktopName = config.name; desktopName = config.name;
mimeType = ifNotNull config.mimeType (semicolonList config.mimeType); mimeTypes = optionals (config.mimeType != null) config.mimeType;
categories = categories = optionals (config.categories != null) config.categories;
ifNotNull config.categories (semicolonList config.categories); extraConfig = config.settings;
extraEntries = config.extraConfig;
extraDesktopEntries = config.settings;
}; };
in { in {
meta.maintainers = [ hm.maintainers.cwyc ]; meta.maintainers = [ hm.maintainers.cwyc ];
@ -182,7 +179,7 @@ in {
config = mkIf (config.xdg.desktopEntries != { }) { config = mkIf (config.xdg.desktopEntries != { }) {
assertions = [ assertions = [
(hm.assertions.assertPlatform "xdg.desktopEntries" pkgs platforms.linux) (hm.assertions.assertPlatform "xdg.desktopEntries" pkgs platforms.linux)
]; ] ++ flatten (catAttrs "assertions" (attrValues config.xdg.desktopEntries));
home.packages = (map hiPrio # we need hiPrio to override existing entries home.packages = (map hiPrio # we need hiPrio to override existing entries
(attrsets.mapAttrsToList makeFile config.xdg.desktopEntries)); (attrsets.mapAttrsToList makeFile config.xdg.desktopEntries));

View file

@ -48,6 +48,13 @@ with lib;
}) })
]; ];
test.asserts.assertions.expected =
let currentFile = toString ./desktop-entries.nix;
in [''
The option definition `extraConfig' in `${currentFile}' no longer has any effect; please remove it.
The `extraConfig` option of `xdg.desktopEntries` has been removed following a change in Nixpkgs.
''];
nmt.script = '' nmt.script = ''
assertFileExists home-path/share/applications/full.desktop assertFileExists home-path/share/applications/full.desktop
assertFileExists home-path/share/applications/min.desktop assertFileExists home-path/share/applications/min.desktop

View file

@ -1,18 +1,16 @@
[Desktop Entry] [Desktop Entry]
Categories=Network;WebBrowser; Categories=Network;WebBrowser
Comment=My Application Comment=My Application
DBusActivatable=false DBusActivatable=false
Exec=test --option Exec=test --option
GenericName=Web Browser GenericName=Web Browser
Icon=test Icon=test
Keywords=calc;math Keywords=calc;math
MimeType=text/html;text/xml; MimeType=text/html;text/xml
Name=Test Name=Test
NoDisplay=false NoDisplay=false
PrefersNonDefaultGPU=false PrefersNonDefaultGPU=false
StartupNotify=false StartupNotify=false
Terminal=true Terminal=true
Type=Application Type=Application
[X-ExtraSection] Version=1.4
Exec=foo -o

View file

@ -3,3 +3,4 @@ Exec=test --option
Name=Test Name=Test
Terminal=false Terminal=false
Type=Application Type=Application
Version=1.4