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
22postInstallHooks+=(copyDesktopItems)
23
24copyDesktopItems() {
25 if [ "${dontCopyDesktopItems-}" = 1 ]; then return; fi
26
27 if [ -z "$desktopItems" ]; then
28 return
29 fi
30
31 applications="${!outputBin}/share/applications"
32 for desktopItem in $desktopItems; do
33 if [[ -f "$desktopItem" ]]; then
34 echo "Copying '$desktopItem' into '${applications}'"
35 install -D -m 444 -t "${applications}" "$desktopItem"
36 else
37 for f in "$desktopItem"/share/applications/*.desktop; do
38 echo "Copying '$f' into '${applications}'"
39 install -D -m 444 -t "${applications}" "$f"
40 done
41 fi
42 done
43}