diff --git a/modules/misc/xdg-desktop-entries.nix b/modules/misc/xdg-desktop-entries.nix index c0b110fa..9b75910a 100644 --- a/modules/misc/xdg-desktop-entries.nix +++ b/modules/misc/xdg-desktop-entries.nix @@ -4,8 +4,12 @@ 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, + # 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`. @@ -13,14 +17,10 @@ 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: + # Descriptions are taken from the desktop entry spec: # https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#recognized-keys type = mkOption { @@ -31,7 +31,7 @@ let exec = mkOption { description = "Program to execute, possibly with arguments."; - type = types.str; + type = types.nullOr types.str; }; icon = mkOption { @@ -78,9 +78,9 @@ let startupNotify = mkOption { description = '' - If true, it is KNOWN that the application will send a "remove" - message when started with the DESKTOP_STARTUP_ID - environment variable set. If false, it is KNOWN that the application + If true, it is KNOWN that the application will send a "remove" + message when started with the DESKTOP_STARTUP_ID + 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; @@ -103,19 +103,10 @@ 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 = '' - Extra key-value pairs to add to the [Desktop Entry] section. + Extra key-value pairs to add to the [Desktop Entry] section. This may override other values. ''; default = { }; @@ -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)); diff --git a/tests/modules/misc/xdg/desktop-entries.nix b/tests/modules/misc/xdg/desktop-entries.nix index adb6e31e..233c0eea 100644 --- a/tests/modules/misc/xdg/desktop-entries.nix +++ b/tests/modules/misc/xdg/desktop-entries.nix @@ -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 diff --git a/tests/modules/misc/xdg/desktop-full-expected.desktop b/tests/modules/misc/xdg/desktop-full-expected.desktop index 7776e8b7..784b6d83 100644 --- a/tests/modules/misc/xdg/desktop-full-expected.desktop +++ b/tests/modules/misc/xdg/desktop-full-expected.desktop @@ -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 diff --git a/tests/modules/misc/xdg/desktop-min-expected.desktop b/tests/modules/misc/xdg/desktop-min-expected.desktop index 9475024a..1b36b57c 100644 --- a/tests/modules/misc/xdg/desktop-min-expected.desktop +++ b/tests/modules/misc/xdg/desktop-min-expected.desktop @@ -3,3 +3,4 @@ Exec=test --option Name=Test Terminal=false Type=Application +Version=1.4