lol
1{ lib, stdenv, fetchurl, fetchFromGitHub, makeWrapper
2, meson
3, ninja
4, pkg-config
5, installShellFiles
6
7, platform-tools
8, ffmpeg
9, libusb1
10, SDL2
11}:
12
13let
14 version = "1.24";
15 prebuilt_server = fetchurl {
16 url = "https://github.com/Genymobile/scrcpy/releases/download/v${version}/scrcpy-server-v${version}";
17 sha256 = "sha256-rnSoHqecDcclDlhmJ8J4wKmoxd5GyftcOMFn+xo28FY=";
18 };
19in
20stdenv.mkDerivation rec {
21 pname = "scrcpy";
22 inherit version;
23
24 src = fetchFromGitHub {
25 owner = "Genymobile";
26 repo = pname;
27 rev = "v${version}";
28 sha256 = "sha256-mL0lSZUPMMcLGq4iPp/IgYZLaTeey9Nv9vVwY1gaIRk=";
29 };
30
31 # postPatch:
32 # screen.c: When run without a hardware accelerator, this allows the command to continue working rather than failing unexpectedly.
33 # This can happen when running on non-NixOS because then scrcpy seems to have a hard time using the host OpenGL-supporting hardware.
34 # It would be better to fix the OpenGL problem, but that seems much more intrusive.
35 postPatch = ''
36 substituteInPlace app/src/screen.c \
37 --replace "SDL_RENDERER_ACCELERATED" "SDL_RENDERER_ACCELERATED || SDL_RENDERER_SOFTWARE"
38 '';
39
40 nativeBuildInputs = [ makeWrapper meson ninja pkg-config installShellFiles ];
41
42 buildInputs = [ ffmpeg SDL2 libusb1 ];
43
44 # Manually install the server jar to prevent Meson from "fixing" it
45 preConfigure = ''
46 echo -n > server/meson.build
47 '';
48
49 postInstall = ''
50 mkdir -p "$out/share/scrcpy"
51 ln -s "${prebuilt_server}" "$out/share/scrcpy/scrcpy-server"
52
53 # runtime dep on `adb` to push the server
54 wrapProgram "$out/bin/scrcpy" --prefix PATH : "${platform-tools}/bin"
55 '';
56
57 meta = with lib; {
58 description = "Display and control Android devices over USB or TCP/IP";
59 homepage = "https://github.com/Genymobile/scrcpy";
60 sourceProvenance = with sourceTypes; [
61 fromSource
62 binaryBytecode # server
63 ];
64 license = licenses.asl20;
65 platforms = platforms.unix;
66 maintainers = with maintainers; [ deltaevo lukeadams msfjarvis ];
67 };
68}