1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-27 05:29:46 +01:00

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,6 +4,10 @@ with lib;
let
desktopEntry = {
imports = [
(mkRemovedOptionModule [ "extraConfig" ]
"The `extraConfig` option of `xdg.desktopEntries` has been removed following a change in Nixpkgs.")
];
options = {
# Since this module uses the nixpkgs/pkgs/build-support/make-desktopitem function,
# our options and defaults follow its parameters, with the following exceptions:
@ -13,13 +17,9 @@ let
# `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`,
# `extraConfig` on makeDesktopItem is controlled 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;",
# 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
@ -31,7 +31,7 @@ let
exec = mkOption {
description = "Program to execute, possibly with arguments.";
type = types.str;
type = types.nullOr types.str;
};
icon = mkOption {
@ -103,15 +103,6 @@ let
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 {
type = types.attrsOf types.string;
description = ''
@ -132,11 +123,19 @@ let
description = "Whether to validate the generated desktop file.";
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
ifNotNull = a: a': if a == null then null else a';
semicolonList = list:
(concatStringsSep ";" list) + ";"; # requires trailing semicolon
@ -148,11 +147,9 @@ let
type exec icon comment terminal genericName startupNotify noDisplay
prefersNonDefaultGPU;
desktopName = config.name;
mimeType = ifNotNull config.mimeType (semicolonList config.mimeType);
categories =
ifNotNull config.categories (semicolonList config.categories);
extraEntries = config.extraConfig;
extraDesktopEntries = config.settings;
mimeTypes = optionals (config.mimeType != null) config.mimeType;
categories = optionals (config.categories != null) config.categories;
extraConfig = config.settings;
};
in {
meta.maintainers = [ hm.maintainers.cwyc ];
@ -182,7 +179,7 @@ in {
config = mkIf (config.xdg.desktopEntries != { }) {
assertions = [
(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
(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 = ''
assertFileExists home-path/share/applications/full.desktop
assertFileExists home-path/share/applications/min.desktop

View file

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

View file

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