3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/build-support/make-desktopitem/default.nix
Bjørn Forsman e488670764 makeDesktopItem: use runCommandLocal
This derivation only creates a simple text file, so it makes sense to do
it locally.

On my setup this reduces build time from 2.2s to 1.2s.
2019-12-08 20:47:27 +01:00

44 lines
1.1 KiB
Nix

{ lib, runCommandLocal }:
{ name
, type ? "Application"
, exec
, icon ? null
, comment ? null
, terminal ? "false"
, desktopName
, genericName ? null
, mimeType ? null
, categories ? "Application;Other;"
, startupNotify ? null
, extraEntries ? null
}:
let
optionalEntriesList = [{k="Icon"; v=icon;}
{k="Comment"; v=comment;}
{k="GenericName"; v=genericName;}
{k="MimeType"; v=mimeType;}
{k="StartupNotify"; v=startupNotify;}];
valueNotNull = {k, v}: v != null;
entriesToKeep = builtins.filter valueNotNull optionalEntriesList;
mkEntry = {k, v}: k + "=" + v;
optionalEntriesString = lib.concatMapStringsSep "\n" mkEntry entriesToKeep;
in
runCommandLocal "${name}.desktop" {}
''
mkdir -p $out/share/applications
cat > $out/share/applications/${name}.desktop <<EOF
[Desktop Entry]
Type=${type}
Exec=${exec}
Terminal=${terminal}
Name=${desktopName}
Categories=${categories}
${optionalEntriesString}
${if extraEntries == null then ''EOF'' else ''
${extraEntries}
EOF''}
''