summary refs log tree commit diff
path: root/pkgs/build-support/kde/wrapper.nix
blob: 4442b111d79041eb8e831389a75165ec4ac9b03f (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{ stdenv, lib, makeWrapper, buildEnv, gtk3, dconf }:

packages:

let
  packages_ = if builtins.isList packages then packages else [packages];

  unwrapped = lib.concatMap (p: if builtins.isList p.unwrapped then p.unwrapped else [p.unwrapped]) packages_;
  targets = lib.concatMap (p: p.targets) packages_;
  paths = lib.concatMap (p: p.paths or []) packages_;

  name =
    if builtins.length unwrapped == 1
    then (lib.head unwrapped).name
    else "kde-application";
  meta =
    if builtins.length unwrapped == 1
    then (lib.head unwrapped).meta
    else {};

  env = buildEnv {
    inherit name meta;
    paths = builtins.map lib.getBin (unwrapped ++ paths);
    pathsToLink = [ "/bin" "/share" "/lib/qt5" "/etc/xdg" ];
  };
in

stdenv.mkDerivation {
  inherit name meta;
  preferLocalBuild = true;

  inherit unwrapped env targets;

  passthru = {
    inherit targets paths;
    unwrapped = if builtins.length unwrapped == 1 then lib.head unwrapped else unwrapped;
  };

  nativeBuildInputs = [ makeWrapper ];

  buildCommand = ''
    for t in $targets; do
        good=""
        for drv in $unwrapped; do
            if [ -a "$drv/$t" ]; then
                makeWrapper "$drv/$t" "$out/$t" \
                    --argv0 '"$0"' \
                    --suffix PATH : "$env/bin" \
                    --prefix XDG_CONFIG_DIRS : "$env/etc/xdg" \
                    --prefix XDG_DATA_DIRS : "$env/share:${gtk3}/share/gsettings-schemas/${gtk3.name}" \
                    --prefix QML_IMPORT_PATH : "$env/lib/qt5/imports" \
                    --prefix QML2_IMPORT_PATH : "$env/lib/qt5/qml" \
                    --prefix QT_PLUGIN_PATH : "$env/lib/qt5/plugins" \
                    --prefix GIO_EXTRA_MODULES : "${dconf.lib}/lib/gio/modules"
                good="1"
                break
            fi
        done
        if [ -z "$good" ]; then
            echo "file or directory not found in derivations: $t"
            exit 1
        fi
    done

    mkdir -p "$out/nix-support"
    echo "$unwrapped" > "$out/nix-support/propagated-user-env-packages"
  '';
}