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