about summary refs log tree commit diff
path: root/pkgs/build-support/setup-hooks/copy-desktop-items.sh
diff options
context:
space:
mode:
authorFabian Möller <fabianm88@gmail.com>2020-11-27 13:41:09 +0100
committerMilan Pässler <milan@petabyte.dev>2020-11-29 04:03:38 +0100
commit50f54c5ca752ed3831bdf81f486468b9937e49bd (patch)
tree65aa536ae55bb46e30a2987b108de677905954f3 /pkgs/build-support/setup-hooks/copy-desktop-items.sh
parent32c7524f78f3f0928282d75b9546edf5e2514988 (diff)
copyDesktopItems: add new setup-hook
Diffstat (limited to 'pkgs/build-support/setup-hooks/copy-desktop-items.sh')
-rw-r--r--pkgs/build-support/setup-hooks/copy-desktop-items.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/pkgs/build-support/setup-hooks/copy-desktop-items.sh b/pkgs/build-support/setup-hooks/copy-desktop-items.sh
new file mode 100644
index 0000000000000..f96a10f33d5cb
--- /dev/null
+++ b/pkgs/build-support/setup-hooks/copy-desktop-items.sh
@@ -0,0 +1,42 @@
+# shellcheck shell=bash
+
+# Setup hook that installs specified desktop items.
+#
+# Example usage in a derivation:
+#
+#   { …, makeDesktopItem, copyDesktopItems, … }:
+#
+#   let desktopItem = makeDesktopItem { … }; in
+#   stdenv.mkDerivation {
+#     …
+#     nativeBuildInputs = [ copyDesktopItems ];
+#
+#     desktopItems =  [ desktopItem ];
+#     …
+#   }
+#
+# This hook will copy files which are either given by full path
+# or all '*.desktop' files placed inside the 'share/applications'
+# folder of each `desktopItems` argument.
+
+postInstallHooks+=(copyDesktopItems)
+
+copyDesktopItems() {
+    if [ "${dontCopyDesktopItems-}" = 1 ]; then return; fi
+
+    if [ -z "$desktopItems" ]; then
+        return
+    fi
+
+    for desktopItem in $desktopItems; do
+        if [[ -f "$desktopItem" ]]; then
+            echo "Copying '$f' into '$out/share/applications'"
+            install -D -m 444 -t "$out"/share/applications "$f"
+        else
+            for f in "$desktopItem"/share/applications/*.desktop; do
+                echo "Copying '$f' into '$out/share/applications'"
+                install -D -m 444 -t "$out"/share/applications "$f"
+            done
+        fi
+    done
+}