Skip to content

Commit

Permalink
xdg-desktop-entries: adapt to changes in makeDesktopItem
Browse files Browse the repository at this point in the history
This package depends on the makeDesktopItem function in nixpkgs, which recently changed its syntax:
NixOS/nixpkgs#91790

This commit makes the module compatible with the new syntax.

It also exposes the fileValidation option in makeDesktopItem.
  • Loading branch information
--get authored and cwyc committed Oct 24, 2020
1 parent bfc46c0 commit ef2e814
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 23 deletions.
40 changes: 31 additions & 9 deletions modules/misc/xdg-desktop-entries.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ 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`
# `extraEntries` on makeDesktopItem is controlled by `extraConfig`,
# and `extraDesktopEntries` by `settings`,
# to match what's commonly used by other home manager modules.

# `terminal` and `startupNotify` on makeDesktopItem ask for "true" or "false" strings,
# `startupNotify` on makeDesktopItem asks for "true" or "false" strings,
# for usability's sake we ask for a boolean.

# `mimeType` and `categories` on makeDesktopItem ask for a string in the format "one;two;three;",
# for the same reason we ask for a list of strings.

# `fileValidation` isn't exposed for simplicity's sake

# Descriptions are taken from the desktop entry spec:
# https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#recognized-keys

Expand Down Expand Up @@ -91,9 +90,31 @@ let
};

extraConfig = mkOption {
description = "Extra lines to add to the desktop file.";
type = types.nullOr types.lines;
default = null;
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.
This may override other values.
'';
default = { };
example = {
Keywords = "calc;math";
DBusActivatable = "false";
};
};

fileValidation = mkOption {
type = types.bool;
description = "Whether to validate the generated desktop file.";
default = true;
};
};
};
Expand All @@ -104,15 +125,15 @@ let
semicolonList = list:
(concatStringsSep ";" list) + ";"; # requires trailing semicolon

#passing config options to makeDesktopItem in expected format
#passes config options to makeDesktopItem in expected format
makeFile = name: config:
pkgs.makeDesktopItem {
name = name;
type = config.type;
exec = config.exec;
icon = config.icon;
comment = config.comment;
terminal = ifNotNull config.terminal (stringBool config.terminal);
terminal = config.terminal;
desktopName = config.name;
genericName = config.genericName;
mimeType = ifNotNull config.mimeType (semicolonList config.mimeType);
Expand All @@ -121,6 +142,7 @@ let
startupNotify =
ifNotNull config.startupNotify (stringBool config.startupNotify);
extraEntries = config.extraConfig;
extraDesktopEntries = config.settings;
};
in {
meta.maintainers = with maintainers; [ cwyc ];
Expand Down
11 changes: 8 additions & 3 deletions tests/modules/misc/xdg/desktop-entries.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ with lib;
name = "Test";
genericName = "Web Browser";
mimeType = [ "text/html" "text/xml" ];
categories = [ "Application" "Network" "WebBrowser" ];
categories = [ "Network" "WebBrowser" ];
startupNotify = false;
extraConfig = ''
NoDisplay=false
DBusActivatable=false
[X-ExtraSection]
Exec=foo -o
'';
settings = {
Keywords = "calc;math";
DBusActivatable = "false";
};
fileValidation = true;
};
min = { # minimal definition
exec = "test --option";
Expand Down
18 changes: 10 additions & 8 deletions tests/modules/misc/xdg/desktop-full-expected.desktop
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
[Desktop Entry]
Type=Application
Exec=test --option
Terminal=true
Name=Test
Icon=test
Categories=Network;WebBrowser;
Comment=My Application
DBusActivatable=false
Exec=test --option
GenericName=Web Browser
Icon=test
Keywords=calc;math
MimeType=text/html;text/xml;
Categories=Application;Network;WebBrowser;
Name=Test
StartupNotify=false
NoDisplay=false
DBusActivatable=false
Terminal=true
Type=Application
[X-ExtraSection]
Exec=foo -o

5 changes: 2 additions & 3 deletions tests/modules/misc/xdg/desktop-min-expected.desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[Desktop Entry]
Type=Application
Exec=test --option
Terminal=false
Name=Test

Terminal=false
Type=Application

0 comments on commit ef2e814

Please sign in to comment.