summaryrefslogtreecommitdiff
path: root/pkgs/development/mobile/androidenv/emulator.nix
blob: aacd4a50f780f21e5b470f964c25321222506967 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{
  deployAndroidPackage,
  lib,
  stdenv,
  package,
  os,
  arch,
  autoPatchelfHook,
  makeWrapper,
  pkgs,
  pkgsi686Linux,
  postInstall,
  meta,
}:

deployAndroidPackage {
  inherit package os arch;
  nativeBuildInputs = [ makeWrapper ] ++ lib.optionals (os == "linux") [ autoPatchelfHook ];
  buildInputs =
    lib.optionals (os == "linux") (
      with pkgs;
      [
        glibc
        libcxx
        libpulseaudio
        libtiff
        libuuid
        zlib
        libbsd
        ncurses5
        libdrm
        stdenv.cc.cc
        expat
        freetype
        nss
        nspr
        alsa-lib
        waylandpp.lib
        libgbm
      ]
    )
    ++ (with pkgs; [
      libx11
      libxext
      libxdamage
      libxfixes
      libxcb
      libxcomposite
      libxcursor
      libxi
      libxrender
      libxtst
      libice
      libsm
      libxkbfile
      libxshmfence
    ])
    ++ lib.optional (os == "linux" && stdenv.hostPlatform.isx86_64) pkgsi686Linux.glibc;
  patchInstructions =
    (lib.optionalString (os == "linux") ''
      addAutoPatchelfSearchPath $packageBaseDir/lib
      addAutoPatchelfSearchPath $packageBaseDir/lib64
      addAutoPatchelfSearchPath $packageBaseDir/lib64/qt/lib
      # autoPatchelf is not detecting libuuid :(
      addAutoPatchelfSearchPath ${pkgs.libuuid.out}/lib

      # This library is linked against a version of libtiff that nixpkgs doesn't have
      for file in $out/libexec/android-sdk/emulator/*/qt/plugins/imageformats/libqtiffAndroidEmu.so; do
        patchelf --replace-needed libtiff.so.5 libtiff.so "$file" || true
      done

      autoPatchelf $out

      # Wrap emulator so that it can load required libraries at runtime
      wrapProgram $out/libexec/android-sdk/emulator/emulator \
        --prefix LD_LIBRARY_PATH : ${
          lib.makeLibraryPath [
            pkgs.dbus
            pkgs.systemd
            pkgs.libGL
          ]
        } \
        --set QT_XKB_CONFIG_ROOT ${pkgs.xkeyboard_config}/share/X11/xkb \
        --set QTCOMPOSE ${pkgs.libx11.out}/share/X11/locale \
        --set-default VK_ADD_DRIVER_FILES /run/opengl-driver/share/vulkan/icd.d
    '')
    + ''
      mkdir -p $out/bin
      cd $out/bin
      find $out/libexec/android-sdk/emulator -type f -executable -mindepth 1 -maxdepth 1 | while read i; do
        ln -s $i
      done

      cd $out/libexec/android-sdk
      ${postInstall}
    '';
  dontMoveLib64 = true;

  inherit meta;
}