make-desktopitem: make genericName optional

+25 -13
+25 -13
pkgs/build-support/make-desktopitem/default.nix
··· 1 - {stdenv}: 1 + {stdenv, lib}: 2 2 { name 3 3 , type ? "Application" 4 4 , exec 5 - , icon ? "" 6 - , comment ? "" 5 + , icon ? null 6 + , comment ? null 7 7 , terminal ? "false" 8 8 , desktopName 9 - , genericName 10 - , mimeType ? "" 9 + , genericName ? null 10 + , mimeType ? null 11 11 , categories ? "Application;Other;" 12 12 , startupNotify ? null 13 - , extraEntries ? "" 13 + , extraEntries ? null 14 14 }: 15 15 16 16 stdenv.mkDerivation { 17 17 name = "${name}.desktop"; 18 - buildCommand = '' 18 + 19 + buildCommand = let 20 + 21 + optionalEntriesList = [{k="Icon"; v=icon;} 22 + {k="Comment"; v=comment;} 23 + {k="GenericName"; v=genericName;} 24 + {k="MimeType"; v=mimeType;} 25 + {k="StartupNotify"; v=startupNotify;}]; 26 + 27 + valueNotNull = {k, v}: v != null; 28 + entriesToKeep = builtins.filter valueNotNull optionalEntriesList; 29 + 30 + mkEntry = {k, v}: k + "=" + v; 31 + optionalEntriesString = lib.concatMapStringsSep "\n" mkEntry entriesToKeep; 32 + 33 + in 34 + '' 19 35 mkdir -p $out/share/applications 20 36 cat > $out/share/applications/${name}.desktop <<EOF 21 37 [Desktop Entry] 22 38 Type=${type} 23 39 Exec=${exec} 24 - Icon=${icon} 25 - Comment=${comment} 26 40 Terminal=${terminal} 27 41 Name=${desktopName} 28 - GenericName=${genericName} 29 - MimeType=${mimeType} 30 42 Categories=${categories} 43 + ${optionalEntriesString} 44 + ${if extraEntries == null then ''EOF'' else '' 31 45 ${extraEntries} 32 - ${if startupNotify == null then ''EOF'' else '' 33 - StartupNotify=${startupNotify} 34 46 EOF''} 35 47 ''; 36 48 }