···1+# shellcheck shell=bash
2+3+# Setup hook that installs specified desktop items.
4+#
5+# Example usage in a derivation:
6+#
7+# { …, makeDesktopItem, copyDesktopItems, … }:
8+#
9+# let desktopItem = makeDesktopItem { … }; in
10+# stdenv.mkDerivation {
11+# …
12+# nativeBuildInputs = [ copyDesktopItems ];
13+#
14+# desktopItems = [ desktopItem ];
15+# …
16+# }
17+#
18+# This hook will copy files which are either given by full path
19+# or all '*.desktop' files placed inside the 'share/applications'
20+# folder of each `desktopItems` argument.
21+22+postInstallHooks+=(copyDesktopItems)
23+24+copyDesktopItems() {
25+ if [ "${dontCopyDesktopItems-}" = 1 ]; then return; fi
26+27+ if [ -z "$desktopItems" ]; then
28+ return
29+ fi
30+31+ for desktopItem in $desktopItems; do
32+ if [[ -f "$desktopItem" ]]; then
33+ echo "Copying '$f' into '$out/share/applications'"
34+ install -D -m 444 -t "$out"/share/applications "$f"
35+ else
36+ for f in "$desktopItem"/share/applications/*.desktop; do
37+ echo "Copying '$f' into '$out/share/applications'"
38+ install -D -m 444 -t "$out"/share/applications "$f"
39+ done
40+ fi
41+ done
42+}