2019-12-16 01:04:10 +01:00
|
|
|
{ lib, runCommandLocal, desktop-file-utils }:
|
|
|
|
|
2009-05-10 14:03:53 +02:00
|
|
|
{ name
|
|
|
|
, type ? "Application"
|
|
|
|
, exec
|
2016-11-22 01:43:03 +01:00
|
|
|
, icon ? null
|
|
|
|
, comment ? null
|
2009-05-10 14:03:53 +02:00
|
|
|
, terminal ? "false"
|
|
|
|
, desktopName
|
2016-11-22 01:43:03 +01:00
|
|
|
, genericName ? null
|
|
|
|
, mimeType ? null
|
2020-03-31 06:04:02 +02:00
|
|
|
, categories ? null
|
2015-12-13 00:25:56 +01:00
|
|
|
, startupNotify ? null
|
2016-11-22 01:43:03 +01:00
|
|
|
, extraEntries ? null
|
2019-12-16 01:04:10 +01:00
|
|
|
, fileValidation ? true # whether to validate resulting desktop file.
|
2009-05-10 14:03:53 +02:00
|
|
|
}:
|
|
|
|
|
2019-12-04 22:19:21 +01:00
|
|
|
let
|
|
|
|
optionalEntriesList = [{k="Icon"; v=icon;}
|
|
|
|
{k="Comment"; v=comment;}
|
|
|
|
{k="GenericName"; v=genericName;}
|
|
|
|
{k="MimeType"; v=mimeType;}
|
2020-03-31 06:04:02 +02:00
|
|
|
{k="Categories"; v=categories;}
|
2019-12-04 22:19:21 +01:00
|
|
|
{k="StartupNotify"; v=startupNotify;}];
|
2016-11-22 01:43:03 +01:00
|
|
|
|
2019-12-04 22:19:21 +01:00
|
|
|
valueNotNull = {k, v}: v != null;
|
|
|
|
entriesToKeep = builtins.filter valueNotNull optionalEntriesList;
|
2016-11-22 01:43:03 +01:00
|
|
|
|
2019-12-04 22:19:21 +01:00
|
|
|
mkEntry = {k, v}: k + "=" + v;
|
|
|
|
optionalEntriesString = lib.concatMapStringsSep "\n" mkEntry entriesToKeep;
|
|
|
|
in
|
|
|
|
runCommandLocal "${name}.desktop" {}
|
2016-11-22 01:43:03 +01:00
|
|
|
''
|
2019-12-16 01:04:10 +01:00
|
|
|
mkdir -p "$out/share/applications"
|
|
|
|
cat > "$out/share/applications/${name}.desktop" <<EOF
|
2009-05-10 14:03:53 +02:00
|
|
|
[Desktop Entry]
|
|
|
|
Type=${type}
|
|
|
|
Exec=${exec}
|
|
|
|
Terminal=${terminal}
|
|
|
|
Name=${desktopName}
|
2016-11-22 01:43:03 +01:00
|
|
|
${optionalEntriesString}
|
|
|
|
${if extraEntries == null then ''EOF'' else ''
|
2016-02-29 20:42:58 +01:00
|
|
|
${extraEntries}
|
2015-12-13 00:25:56 +01:00
|
|
|
EOF''}
|
2019-12-16 01:04:10 +01:00
|
|
|
|
|
|
|
${lib.optionalString fileValidation ''
|
|
|
|
echo "Running desktop-file validation"
|
|
|
|
${desktop-file-utils}/bin/desktop-file-validate "$out/share/applications/${name}.desktop"
|
|
|
|
''}
|
2019-12-04 22:19:21 +01:00
|
|
|
''
|