summary refs log tree commit diff
path: root/pkgs/build-support/make-desktopitem/default.nix
blob: f8c31ed5c1d424f84a3d6ef90ac44bf04a503ba5 (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
43
44
45
46
47
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''}
  '';
}