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.
This commit is contained in:
Bjørn Forsman 2019-12-04 22:19:21 +01:00
parent 5b6e958b92
commit e488670764

View File

@ -1,4 +1,4 @@
{stdenv, lib}:
{ lib, runCommandLocal }:
{ name
, type ? "Application"
, exec
@ -13,24 +13,20 @@
, extraEntries ? null
}:
stdenv.mkDerivation {
name = "${name}.desktop";
let
optionalEntriesList = [{k="Icon"; v=icon;}
{k="Comment"; v=comment;}
{k="GenericName"; v=genericName;}
{k="MimeType"; v=mimeType;}
{k="StartupNotify"; v=startupNotify;}];
buildCommand = let
valueNotNull = {k, v}: v != null;
entriesToKeep = builtins.filter valueNotNull optionalEntriesList;
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
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
@ -44,5 +40,4 @@ stdenv.mkDerivation {
${if extraEntries == null then ''EOF'' else ''
${extraEntries}
EOF''}
'';
}
''