summary refs log tree commit diff
path: root/pkgs/build-support/setup-hooks/copy-desktop-items.sh
blob: f96a10f33d5cb87ba4fa3b52e62722e6dd0f394f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
}