about summary refs log tree commit diff
path: root/nixpkgs/pkgs/build-support/make-desktopitem
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/build-support/make-desktopitem')
-rw-r--r--nixpkgs/pkgs/build-support/make-desktopitem/default.nix48
1 files changed, 48 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/build-support/make-desktopitem/default.nix b/nixpkgs/pkgs/build-support/make-desktopitem/default.nix
new file mode 100644
index 000000000000..f8c31ed5c1d4
--- /dev/null
+++ b/nixpkgs/pkgs/build-support/make-desktopitem/default.nix
@@ -0,0 +1,48 @@
+{stdenv, lib}:
+{ name
+, type ? "Application"
+, exec
+, icon ? null
+, comment ? null
+, terminal ? "false"
+, desktopName
+, genericName ? null
+, mimeType ? null
+, categories ? "Application;Other;"
+, startupNotify ? null
+, extraEntries ? null
+}:
+
+stdenv.mkDerivation {
+  name = "${name}.desktop";
+
+  buildCommand = 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
+  ''
+    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''}
+  '';
+}