summary refs log tree commit diff
path: root/pkgs/applications/emulators/86box/default.nix
blob: e14d3d0d71370f23131fba9f865dab9d7b167921 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{ stdenv, lib, fetchFromGitHub, cmake, pkg-config, makeWrapper, freetype, SDL2
, glib, pcre2, openal, rtmidi, fluidsynth, jack2, alsa-lib, qt5, libvncserver
, discord-gamesdk, libpcap, libslirp

, enableDynarec ? with stdenv.hostPlatform; isx86 || isAarch
, enableNewDynarec ? enableDynarec && stdenv.hostPlatform.isAarch
, enableVncRenderer ? false
, unfreeEnableDiscord ? false
}:

stdenv.mkDerivation rec {
  pname = "86Box";
  version = "4.0";

  src = fetchFromGitHub {
    owner = "86Box";
    repo = "86Box";
    rev = "v${version}";
    hash = "sha256-VTfYCVEbArcYVzh3NkX1yBXhtRnGZ/+khk0KG42fs24=";
  };

  nativeBuildInputs = [
    cmake
    pkg-config
    makeWrapper
    qt5.wrapQtAppsHook
  ];

  buildInputs = [
    freetype
    fluidsynth
    SDL2
    glib
    openal
    rtmidi
    pcre2
    jack2
    libpcap
    libslirp
    qt5.qtbase
    qt5.qttools
  ] ++ lib.optional stdenv.isLinux alsa-lib
    ++ lib.optional enableVncRenderer libvncserver;

  cmakeFlags = lib.optional stdenv.isDarwin "-DCMAKE_MACOSX_BUNDLE=OFF"
    ++ lib.optional enableNewDynarec "-DNEW_DYNAREC=ON"
    ++ lib.optional enableVncRenderer "-DVNC=ON"
    ++ lib.optional (!enableDynarec) "-DDYNAREC=OFF"
    ++ lib.optional (!unfreeEnableDiscord) "-DDISCORD=OFF";

  postInstall = lib.optional stdenv.isLinux ''
    install -Dm644 -t $out/share/applications $src/src/unix/assets/net.86box.86Box.desktop

    for size in 48 64 72 96 128 192 256 512; do
      install -Dm644 -t $out/share/icons/hicolor/"$size"x"$size"/apps \
        $src/src/unix/assets/"$size"x"$size"/net.86box.86Box.png
    done;
  '';

  # Some libraries are loaded dynamically, but QLibrary doesn't seem to search
  # the runpath, so use a wrapper instead.
  postFixup = let
    libPath = lib.makeLibraryPath ([
      libpcap
    ] ++ lib.optional unfreeEnableDiscord discord-gamesdk);
    libPathVar = if stdenv.isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH";
  in
  ''
    wrapProgram $out/bin/86Box \
      "''${qtWrapperArgs[@]}" \
      --prefix ${libPathVar} : "${libPath}"
  '';

  # Do not wrap twice.
  dontWrapQtApps = true;

  meta = with lib; {
    description = "Emulator of x86-based machines based on PCem.";
    homepage = "https://86box.net/";
    license = with licenses; [ gpl2Only ] ++ optional unfreeEnableDiscord unfree;
    maintainers = [ maintainers.jchw ];
    platforms = platforms.linux;
  };
}