about summary refs log tree commit diff
path: root/nixpkgs/pkgs/misc/emulators
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2019-01-07 02:18:36 +0000
committerAlyssa Ross <hi@alyssa.is>2019-01-07 02:18:47 +0000
commit36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2 (patch)
treeb3faaf573407b32aa645237a4d16b82778a39a92 /nixpkgs/pkgs/misc/emulators
parent4e31070265257dc67d120c27e0f75c2344fdfa9a (diff)
parentabf060725d7614bd3b9f96764262dfbc2f9c2199 (diff)
downloadnixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.gz
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.bz2
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.lz
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.xz
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.zst
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.zip
Add 'nixpkgs/' from commit 'abf060725d7614bd3b9f96764262dfbc2f9c2199'
git-subtree-dir: nixpkgs
git-subtree-mainline: 4e31070265257dc67d120c27e0f75c2344fdfa9a
git-subtree-split: abf060725d7614bd3b9f96764262dfbc2f9c2199
Diffstat (limited to 'nixpkgs/pkgs/misc/emulators')
-rw-r--r--nixpkgs/pkgs/misc/emulators/atari++/default.nix33
-rw-r--r--nixpkgs/pkgs/misc/emulators/atari800/default.nix41
-rw-r--r--nixpkgs/pkgs/misc/emulators/attract-mode/default.nix33
-rw-r--r--nixpkgs/pkgs/misc/emulators/blastem/default.nix50
-rw-r--r--nixpkgs/pkgs/misc/emulators/bsod/default.nix31
-rw-r--r--nixpkgs/pkgs/misc/emulators/caprice32/default.nix29
-rw-r--r--nixpkgs/pkgs/misc/emulators/ccemux/default.nix66
-rw-r--r--nixpkgs/pkgs/misc/emulators/cdemu/analyzer.nix16
-rw-r--r--nixpkgs/pkgs/misc/emulators/cdemu/base.nix37
-rw-r--r--nixpkgs/pkgs/misc/emulators/cdemu/client.nix16
-rw-r--r--nixpkgs/pkgs/misc/emulators/cdemu/daemon.nix9
-rw-r--r--nixpkgs/pkgs/misc/emulators/cdemu/gui.nix21
-rw-r--r--nixpkgs/pkgs/misc/emulators/cdemu/libmirage.nix9
-rw-r--r--nixpkgs/pkgs/misc/emulators/cdemu/vhba.nix24
-rw-r--r--nixpkgs/pkgs/misc/emulators/citra/default.nix33
-rw-r--r--nixpkgs/pkgs/misc/emulators/darcnes/default.nix24
-rw-r--r--nixpkgs/pkgs/misc/emulators/darcnes/label.patch13
-rw-r--r--nixpkgs/pkgs/misc/emulators/desmume/default.nix58
-rw-r--r--nixpkgs/pkgs/misc/emulators/dlx/default.nix31
-rw-r--r--nixpkgs/pkgs/misc/emulators/dolphin-emu/default.nix48
-rw-r--r--nixpkgs/pkgs/misc/emulators/dolphin-emu/master.nix84
-rw-r--r--nixpkgs/pkgs/misc/emulators/dosbox/default.nix40
-rw-r--r--nixpkgs/pkgs/misc/emulators/emulationstation/default.nix30
-rw-r--r--nixpkgs/pkgs/misc/emulators/epsxe/default.nix56
-rw-r--r--nixpkgs/pkgs/misc/emulators/fakenes/build.patch84
-rw-r--r--nixpkgs/pkgs/misc/emulators/fakenes/default.nix32
-rw-r--r--nixpkgs/pkgs/misc/emulators/fceux/default.nix36
-rw-r--r--nixpkgs/pkgs/misc/emulators/firebird-emu/default.nix38
-rw-r--r--nixpkgs/pkgs/misc/emulators/fs-uae/default.nix32
-rw-r--r--nixpkgs/pkgs/misc/emulators/gens-gs/default.nix25
-rw-r--r--nixpkgs/pkgs/misc/emulators/gxemul/default.nix37
-rw-r--r--nixpkgs/pkgs/misc/emulators/hatari/default.nix23
-rw-r--r--nixpkgs/pkgs/misc/emulators/higan/0001-change-flags.diff26
-rw-r--r--nixpkgs/pkgs/misc/emulators/higan/default.nix84
-rw-r--r--nixpkgs/pkgs/misc/emulators/kega-fusion/default.nix78
-rw-r--r--nixpkgs/pkgs/misc/emulators/libdsk/default.nix19
-rw-r--r--nixpkgs/pkgs/misc/emulators/mednafen/default.nix42
-rw-r--r--nixpkgs/pkgs/misc/emulators/mednafen/server.nix21
-rw-r--r--nixpkgs/pkgs/misc/emulators/mednaffe/default.nix30
-rw-r--r--nixpkgs/pkgs/misc/emulators/mess/default.nix49
-rw-r--r--nixpkgs/pkgs/misc/emulators/mgba/default.nix70
-rw-r--r--nixpkgs/pkgs/misc/emulators/mupen64plus/default.nix29
-rw-r--r--nixpkgs/pkgs/misc/emulators/nestopia/build-fix.patch18
-rw-r--r--nixpkgs/pkgs/misc/emulators/nestopia/default.nix72
-rw-r--r--nixpkgs/pkgs/misc/emulators/nestopia/gcc6.patch92
-rw-r--r--nixpkgs/pkgs/misc/emulators/openmsx/custom-nixos.mk9
-rw-r--r--nixpkgs/pkgs/misc/emulators/openmsx/default.nix48
-rw-r--r--nixpkgs/pkgs/misc/emulators/pcsx2/default.nix74
-rw-r--r--nixpkgs/pkgs/misc/emulators/pcsxr/default.nix87
-rw-r--r--nixpkgs/pkgs/misc/emulators/pcsxr/uncompress2.patch20
-rw-r--r--nixpkgs/pkgs/misc/emulators/ppsspp/default.nix45
-rw-r--r--nixpkgs/pkgs/misc/emulators/qmc2/default.nix40
-rw-r--r--nixpkgs/pkgs/misc/emulators/retroarch/cores.nix456
-rw-r--r--nixpkgs/pkgs/misc/emulators/retroarch/default.nix87
-rw-r--r--nixpkgs/pkgs/misc/emulators/retroarch/kodi-advanced-launchers.nix40
-rw-r--r--nixpkgs/pkgs/misc/emulators/retroarch/wrapper.nix43
-rw-r--r--nixpkgs/pkgs/misc/emulators/retrofe/default.nix78
-rw-r--r--nixpkgs/pkgs/misc/emulators/retrofe/include-paths.patch11
-rw-r--r--nixpkgs/pkgs/misc/emulators/rpcs3/default.nix53
-rw-r--r--nixpkgs/pkgs/misc/emulators/snes9x-gtk/default.nix39
-rw-r--r--nixpkgs/pkgs/misc/emulators/stella/default.nix31
-rw-r--r--nixpkgs/pkgs/misc/emulators/termtekst/default.nix36
-rw-r--r--nixpkgs/pkgs/misc/emulators/uae/default.nix25
-rw-r--r--nixpkgs/pkgs/misc/emulators/vbam/default.nix56
-rw-r--r--nixpkgs/pkgs/misc/emulators/vice/default.nix53
-rw-r--r--nixpkgs/pkgs/misc/emulators/wine/base.nix122
-rw-r--r--nixpkgs/pkgs/misc/emulators/wine/builder-wow.sh32
-rw-r--r--nixpkgs/pkgs/misc/emulators/wine/default.nix67
-rw-r--r--nixpkgs/pkgs/misc/emulators/wine/packages.nix35
-rw-r--r--nixpkgs/pkgs/misc/emulators/wine/sources.nix65
-rw-r--r--nixpkgs/pkgs/misc/emulators/wine/staging.nix24
-rw-r--r--nixpkgs/pkgs/misc/emulators/wine/util.nix9
-rw-r--r--nixpkgs/pkgs/misc/emulators/wine/winetricks.nix32
-rw-r--r--nixpkgs/pkgs/misc/emulators/wxmupen64plus/default.nix30
-rw-r--r--nixpkgs/pkgs/misc/emulators/xcpc/default.nix22
-rw-r--r--nixpkgs/pkgs/misc/emulators/yabause/0001-Fixes-for-Qt-5.11-upgrade.patch67
-rw-r--r--nixpkgs/pkgs/misc/emulators/yabause/default.nix36
-rw-r--r--nixpkgs/pkgs/misc/emulators/yabause/linkage-rwx-linux-elf.patch20
-rw-r--r--nixpkgs/pkgs/misc/emulators/zsnes/default.nix63
79 files changed, 3724 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/misc/emulators/atari++/default.nix b/nixpkgs/pkgs/misc/emulators/atari++/default.nix
new file mode 100644
index 000000000000..5a37b1b32c5b
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/atari++/default.nix
@@ -0,0 +1,33 @@
+{ stdenv, fetchurl, libSM, libX11, libICE, SDL, alsaLib, gcc-unwrapped, libXext }:
+
+with stdenv.lib;
+stdenv.mkDerivation rec{
+  name = "atari++-${version}";
+  version = "1.81";
+
+  src = fetchurl {
+    url = "http://www.xl-project.com/download/atari++_${version}.tar.gz";
+    sha256 = "1sv268dsjddirhx47zaqgqiahy6zjxj7xaiiksd1gjvs4lvf3cdg";
+  };
+
+  buildInputs = [ libSM libX11 SDL libICE alsaLib gcc-unwrapped libXext ];
+
+  postFixup = ''
+    patchelf --set-rpath ${stdenv.lib.makeLibraryPath buildInputs} "$out/bin/atari++"
+  '';
+
+  meta = {
+    homepage = http://www.xl-project.com/;
+    description = "An enhanced, cycle-accurated Atari emulator";
+    longDescription = ''
+      The Atari++ Emulator is a Unix based emulator of the Atari eight
+      bit computers, namely the Atari 400 and 800, the Atari 400XL,
+      800XL and 130XE, and the Atari 5200 game console. The emulator
+      is auto-configurable and will compile on a variety of systems
+      (Linux, Solaris, Irix).
+    '';
+    maintainers = [ maintainers.AndersonTorres ];
+    license = licenses.gpl2Plus;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/atari800/default.nix b/nixpkgs/pkgs/misc/emulators/atari800/default.nix
new file mode 100644
index 000000000000..4806c7f9e0f1
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/atari800/default.nix
@@ -0,0 +1,41 @@
+{ stdenv, fetchurl
+, unzip, zlib, SDL, readline, libGLU_combined, libX11 }:
+
+with stdenv.lib;
+stdenv.mkDerivation rec{
+  name = "atari800-${version}";
+  version = "4.0.0";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/atari800/atari800/${version}/${name}.tar.gz";
+    sha256 = "1dcynsf8i52y7zyg62bkbhl3rdd22ss95zs2s9jm4y5jvn4vks88";
+  };
+
+  buildInputs = [ unzip zlib SDL readline libGLU_combined libX11 ];
+
+  configureFlags = [
+    "--target=default"
+    "--with-video=sdl"
+    "--with-sound=sdl"
+    "--with-readline"
+    "--with-opengl"
+    "--with-x"
+    "--enable-riodevice"
+  ];
+
+  preConfigure = "cd src";
+
+  meta = {
+    homepage = http://atari800.sourceforge.net/;
+    description = "An Atari 8-bit emulator";
+    longDescription = ''
+      Atari800 is the emulator of Atari 8-bit computer systems and
+      5200 game console for Unix, Linux, Amiga, MS-DOS, Atari
+      TT/Falcon, MS-Windows, MS WinCE, Sega Dreamcast, Android and
+      other systems supported by the SDL library.
+    '';
+    maintainers = [ maintainers.AndersonTorres ];
+    license = licenses.gpl2Plus;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/attract-mode/default.nix b/nixpkgs/pkgs/misc/emulators/attract-mode/default.nix
new file mode 100644
index 000000000000..601503dc07ec
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/attract-mode/default.nix
@@ -0,0 +1,33 @@
+{ expat, fetchFromGitHub, ffmpeg, fontconfig, freetype, libarchive, libjpeg
+, libGLU_combined, openal, pkgconfig, sfml, stdenv, zlib
+}:
+
+stdenv.mkDerivation rec {
+  name = "attract-mode-${version}";
+  version = "2.2.0";
+
+  src = fetchFromGitHub {
+    owner = "mickelson";
+    repo = "attract";
+    rev = "v${version}";
+    sha256 = "1arkfj0q3n1qbq5jwmal0kixxph8lnmv3g9bli36inab4r8zzmp8";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+
+  patchPhase = ''
+    sed -i "s|prefix=/usr/local|prefix=$out|" Makefile
+  '';
+
+  buildInputs = [
+    expat ffmpeg fontconfig freetype libarchive libjpeg libGLU_combined openal sfml zlib
+  ];
+
+  meta = with stdenv.lib; {
+    description = "A frontend for arcade cabinets and media PCs";
+    homepage = http://attractmode.org;
+    license = licenses.gpl3Plus;
+    maintainers = with maintainers; [ hrdinka ];
+    platforms = with platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/blastem/default.nix b/nixpkgs/pkgs/misc/emulators/blastem/default.nix
new file mode 100644
index 000000000000..666f953f6b57
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/blastem/default.nix
@@ -0,0 +1,50 @@
+{ stdenv, fetchurl, fetchFromGitHub, pkgconfig, SDL2, glew, xcftools, python, pillow, makeWrapper }:
+
+let
+  vasm =
+    stdenv.mkDerivation rec {
+      name = "vasm-${version}";
+      version = "1.8c";
+      src = fetchFromGitHub {
+        owner = "mbitsnbites";
+        repo = "vasm";
+        rev = "244f8bbbdf64ae603f9f6c09a3067943837459ec";
+        sha256 = "0x4y5q7ygxfjfy2wxijkps9khsjjfb169sbda410vaw0m88wqj5p";
+      };
+      makeFlags = "CPU=m68k SYNTAX=mot";
+      installPhase = ''
+        mkdir -p $out/bin
+        cp vasmm68k_mot $out/bin
+      '';
+    };
+in
+stdenv.mkDerivation rec {
+  name = "blastem-${version}";
+  version = "0.5.1";
+  src = fetchurl {
+    url = "https://www.retrodev.com/repos/blastem/archive/3d48cb0c28be.tar.gz";
+    sha256 = "07wzbmzp0y8mh59jxg81q17gqagz3psxigxh8dmzsipgg68y6a8r";
+  };
+  buildInputs = [ pkgconfig SDL2 glew xcftools python pillow vasm makeWrapper ];
+  preBuild = ''
+    patchShebangs img2tiles.py
+  '';
+  postBuild = ''
+    make menu.bin
+  '';
+  installPhase = ''
+    mkdir -p $out/bin $out/share/blastem
+    cp -r {blastem,menu.bin,default.cfg,rom.db,shaders} $out/share/blastem/
+    makeWrapper $out/share/blastem/blastem $out/bin/blastem
+  '';
+
+  meta = {
+    homepage = https://www.retrodev.com/blastem/;
+    description = "The fast and accurate Genesis emulator";
+    maintainers = with stdenv.lib.maintainers; [ puffnfresh ];
+    license = stdenv.lib.licenses.gpl3;
+    platforms = stdenv.lib.platforms.linux;
+    # Makefile:140: *** aarch64 is not a supported architecture.  Stop.
+    badPlatforms = [ "aarch64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/bsod/default.nix b/nixpkgs/pkgs/misc/emulators/bsod/default.nix
new file mode 100644
index 000000000000..8575d654febf
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/bsod/default.nix
@@ -0,0 +1,31 @@
+{stdenv, fetchurl, ncurses}:
+
+stdenv.mkDerivation {
+  name = "bsod-0.1";
+
+  src = fetchurl {
+    url = https://www.vanheusden.com/bsod/bsod-0.1.tgz;
+    sha256 = "0hqwacazyq5rhc04j8w8w0j0dgb6ca8k66c9lxf6bsyi6wvbhvmd";
+  };
+
+  buildInputs = [ ncurses ];
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp bsod $out/bin
+  '';
+
+  meta = {
+    description = "Blue Screen Of Death emulator for Unix";
+    longDescription = "
+      This program will let you UNIX user experience the authentic
+      microsoft windows experience.  Bsod displays the famous windows xp
+      blue screen of death on the console.  Errors and drivers causing the
+      error are selected randomly from a large set of examples.";
+    homepage = http://www.vanheusden.com/bsod/;
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.unix;
+    maintainers = [ stdenv.lib.maintainers.antono ];
+  };
+
+}
diff --git a/nixpkgs/pkgs/misc/emulators/caprice32/default.nix b/nixpkgs/pkgs/misc/emulators/caprice32/default.nix
new file mode 100644
index 000000000000..42b8e5229e99
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/caprice32/default.nix
@@ -0,0 +1,29 @@
+{ stdenv, fetchFromGitHub, libpng, pkgconfig, SDL, freetype, zlib }:
+
+stdenv.mkDerivation rec {
+
+  repo = "caprice32";
+  version = "unstable-2018-03-05";
+  rev = "317fe638111e245d67e301f6f295094d3c859a70";
+  name = "${repo}-${version}";
+
+  src = fetchFromGitHub {
+    inherit rev repo;
+    owner = "ColinPitrat";
+    sha256 = "1bywpmkizixcnr057k8zq9nlw0zhcmwkiriln0krgdcm7d3h9b86";
+  };
+
+  postPatch = "substituteInPlace cap32.cfg --replace /usr/local $out";
+
+  meta = with stdenv.lib; {
+    description = "A complete emulation of CPC464, CPC664 and CPC6128";
+    homepage = https://github.com/ColinPitrat/caprice32 ;
+    license = licenses.gpl2;
+    maintainers = [ maintainers.genesis ];
+    platforms = platforms.linux;
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ libpng SDL freetype zlib ];
+  makeFlags = [ "GIT_HASH=${src.rev}" "DESTDIR=$(out)" "prefix=/"];
+}
diff --git a/nixpkgs/pkgs/misc/emulators/ccemux/default.nix b/nixpkgs/pkgs/misc/emulators/ccemux/default.nix
new file mode 100644
index 000000000000..bd2be99a2843
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/ccemux/default.nix
@@ -0,0 +1,66 @@
+{ stdenv, fetchurl, fetchFromGitHub, makeDesktopItem, makeWrapper, jre
+, useCCTweaked ? true
+}:
+
+let
+  version = "1.1.0";
+  rev = "a12239148332ca7a0b1c44a93e1585452d3631c9";
+
+  baseUrl = "https://emux.cc/versions/${stdenv.lib.substring 0 8 rev}/CCEmuX";
+  jar =
+    if useCCTweaked
+    then fetchurl {
+      url = "${baseUrl}-cct.jar";
+      sha256 = "1i767v3wnb8jsh7ciqqvw548pka1b8vl18k1rdv5dn21la6n0r1d";
+    }
+    else fetchurl {
+      url = "${baseUrl}-cc.jar";
+      sha256 = "0x9hs814ln193cwybd565mcj6vhnii4wirkiz9na7vcas0y5vmmq";
+    };
+
+  desktopIcon = fetchurl {
+    url = "https://github.com/CCEmuX/CCEmuX/raw/${rev}/src/main/resources/img/icon.png";
+    sha256 = "1vmb6rg9k2y99j8xqfgbsvfgfi3g985rmqwrd7w3y54ffr2r99c2";
+  };
+  desktopItem =  makeDesktopItem {
+    name = "CCEmuX";
+    exec = "ccemux";
+    icon = "${desktopIcon}";
+    comment = "A modular ComputerCraft emulator";
+    desktopName = "CCEmuX";
+    genericName = "ComputerCraft Emulator";
+    categories = "Application;Emulator;";
+  };
+in
+
+stdenv.mkDerivation rec {
+  name = "ccemux-${version}";
+
+  src = jar;
+  unpackPhase = "true";
+
+  nativeBuildInputs = [ makeWrapper ];
+  buildInputs = [ jre ];
+
+  installPhase = ''
+    runHook preInstall
+
+    mkdir -p $out/{bin,share/ccemux}
+    cp -r ${desktopItem}/share/applications $out/share/applications
+
+    install -D ${src} $out/share/ccemux/ccemux.jar
+    install -D ${desktopIcon} $out/share/pixmaps/ccemux.png
+
+    makeWrapper ${jre}/bin/java $out/bin/ccemux \
+      --add-flags "-jar $out/share/ccemux/ccemux.jar"
+
+    runHook postInstall
+  '';
+
+  meta = with stdenv.lib; {
+    description = "A modular ComputerCraft emulator";
+    homepage = https://github.com/CCEmuX/CCEmuX;
+    license = licenses.mit;
+    maintainers = with maintainers; [ CrazedProgrammer ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/cdemu/analyzer.nix b/nixpkgs/pkgs/misc/emulators/cdemu/analyzer.nix
new file mode 100644
index 000000000000..64b485bea310
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/cdemu/analyzer.nix
@@ -0,0 +1,16 @@
+{ callPackage, gtk3, glib, libxml2, gnuplot, makeWrapper, gnome3, gdk_pixbuf, librsvg, intltool }:
+let pkg = import ./base.nix {
+  version = "3.1.0";
+  pkgName = "image-analyzer";
+  pkgSha256 = "1pr23kxx83xp83h27fkdv86f3bxclkx056f9jx8jhnpn113xp7r2";
+};
+in callPackage pkg {
+  buildInputs = [ glib gtk3 libxml2 gnuplot (callPackage ./libmirage.nix {}) makeWrapper
+                  gnome3.defaultIconTheme gdk_pixbuf librsvg intltool ];
+  drvParams = {
+    postFixup = ''
+      wrapProgram $out/bin/image-analyzer \
+        --prefix XDG_DATA_DIRS : "$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH"
+    '';
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/cdemu/base.nix b/nixpkgs/pkgs/misc/emulators/cdemu/base.nix
new file mode 100644
index 000000000000..e587151d3e72
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/cdemu/base.nix
@@ -0,0 +1,37 @@
+{ pkgName, version, pkgSha256 }:
+{ stdenv, fetchurl, cmake, pkgconfig, buildInputs, drvParams ? {} }:
+let name = "${pkgName}-${version}";
+in stdenv.mkDerivation ({
+  inherit name buildInputs;
+  src = fetchurl {
+    url = "mirror://sourceforge/cdemu/${name}.tar.bz2";
+    sha256 = pkgSha256;
+  };
+  nativeBuildInputs = [ pkgconfig cmake ];
+  setSourceRoot = ''
+    mkdir build
+    cd build
+    sourceRoot="`pwd`"
+  '';
+  configurePhase = ''
+    cmake ../${name} -DCMAKE_INSTALL_PREFIX=$out -DCMAKE_BUILD_TYPE=Release -DCMAKE_SKIP_RPATH=ON
+  '';
+  meta = with stdenv.lib; {
+    description = "A suite of tools for emulating optical drives and discs";
+    longDescription = ''
+      CDEmu consists of:
+
+      - a kernel module implementing a virtual drive-controller
+      - libmirage which is a software library for interpreting optical disc images
+      - a daemon which emulates the functionality of an optical drive+disc
+      - textmode and GTK clients for controlling the emulator
+      - an image analyzer to view the structure of image files
+
+      Optical media emulated by CDemu can be mounted within Linux. Automounting is also allowed.
+    '';
+    homepage = http://cdemu.sourceforge.net/;
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = with stdenv.lib.maintainers; [ bendlas ];
+  };
+} // drvParams)
diff --git a/nixpkgs/pkgs/misc/emulators/cdemu/client.nix b/nixpkgs/pkgs/misc/emulators/cdemu/client.nix
new file mode 100644
index 000000000000..ec4341a29459
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/cdemu/client.nix
@@ -0,0 +1,16 @@
+{ callPackage, pythonPackages, intltool, makeWrapper }:
+let pkg = import ./base.nix {
+  version = "3.1.0";
+  pkgName = "cdemu-client";
+  pkgSha256 = "0s6q923g5vkahw5fki6c7a25f68y78zfx4pfsy0xww0z1f5hfsik";
+};
+in callPackage pkg {
+  buildInputs = [ pythonPackages.python pythonPackages.dbus-python pythonPackages.pygobject3
+                  intltool makeWrapper ];
+  drvParams = {
+    postFixup = ''
+      wrapProgram $out/bin/cdemu \
+        --set PYTHONPATH "$PYTHONPATH"
+    '';
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/cdemu/daemon.nix b/nixpkgs/pkgs/misc/emulators/cdemu/daemon.nix
new file mode 100644
index 000000000000..587224e71d78
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/cdemu/daemon.nix
@@ -0,0 +1,9 @@
+{ callPackage, glib, libao, intltool }:
+let pkg = import ./base.nix {
+  version = "3.1.0";
+  pkgName = "cdemu-daemon";
+  pkgSha256 = "0kxwhwjvcr40sjlrvln9gasjwkkfc3wxpcz0rxmffp92w8phz3s9";
+};
+in callPackage pkg {
+  buildInputs = [ glib libao (callPackage ./libmirage.nix {}) intltool ];
+}
diff --git a/nixpkgs/pkgs/misc/emulators/cdemu/gui.nix b/nixpkgs/pkgs/misc/emulators/cdemu/gui.nix
new file mode 100644
index 000000000000..9403a969e8f4
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/cdemu/gui.nix
@@ -0,0 +1,21 @@
+{ callPackage, pythonPackages, gtk3, glib, libnotify, intltool, makeWrapper, gnome3, gdk_pixbuf, librsvg }:
+let
+  pkg = import ./base.nix {
+    version = "3.1.0";
+    pkgName = "gcdemu";
+    pkgSha256 = "0rmnw302fk9vli22v54qx19lqxy23syxi154klxz2vma009q0p02";
+  };
+  inherit (pythonPackages) python pygobject3;
+in callPackage pkg {
+  buildInputs = [ python pygobject3 gtk3 glib libnotify intltool makeWrapper
+                  gnome3.defaultIconTheme gdk_pixbuf librsvg ];
+  drvParams = {
+    postFixup = ''
+      wrapProgram $out/bin/gcdemu \
+        --set PYTHONPATH "$PYTHONPATH" \
+        --set GI_TYPELIB_PATH "$GI_TYPELIB_PATH" \
+        --prefix XDG_DATA_DIRS : "$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH"
+    '';
+    # TODO AppIndicator
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/cdemu/libmirage.nix b/nixpkgs/pkgs/misc/emulators/cdemu/libmirage.nix
new file mode 100644
index 000000000000..3813ceef6115
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/cdemu/libmirage.nix
@@ -0,0 +1,9 @@
+{ callPackage, glib, libsndfile, zlib, bzip2, lzma, libsamplerate, intltool }:
+let pkg = import ./base.nix {
+  version = "3.1.0";
+  pkgName = "libmirage";
+  pkgSha256 = "0qvkvnvxqx8hqzcqzh7sqjzgbc1nrd91lzv33lr8c6fgaq8cqzmn";
+};
+in callPackage pkg {
+  buildInputs = [ glib libsndfile zlib bzip2 lzma libsamplerate intltool ];
+}
diff --git a/nixpkgs/pkgs/misc/emulators/cdemu/vhba.nix b/nixpkgs/pkgs/misc/emulators/cdemu/vhba.nix
new file mode 100644
index 000000000000..73ef7bc6a180
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/cdemu/vhba.nix
@@ -0,0 +1,24 @@
+{ stdenv, fetchurl, kernel }:
+
+stdenv.mkDerivation rec {
+  name = "vhba-${version}";
+  version = "20170610";
+
+  src  = fetchurl {
+    url = "mirror://sourceforge/cdemu/vhba-module-${version}.tar.bz2";
+    sha256 = "1v6r0bgx0a65vlh36b1l2965xybngbpga6rp54k4z74xk0zwjw3r";
+  };
+
+  makeFlags = [ "KDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" "INSTALL_MOD_PATH=$(out)" ];
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  hardeningDisable = [ "pic" ];
+
+  meta = with stdenv.lib; {
+    description = "Provides a Virtual (SCSI) HBA";
+    homepage = http://cdemu.sourceforge.net/about/vhba/;
+    platforms = platforms.linux;
+    license = licenses.gpl2Plus;
+    maintainers = with stdenv.lib.maintainers; [ bendlas ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/citra/default.nix b/nixpkgs/pkgs/misc/emulators/citra/default.nix
new file mode 100644
index 000000000000..1845757fb308
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/citra/default.nix
@@ -0,0 +1,33 @@
+{ stdenv, fetchgit, cmake, SDL2, qtbase, qtmultimedia, boost, curl, gtest }:
+
+stdenv.mkDerivation rec { 
+  name = "citra-${version}";
+  version = "2018-06-09";
+
+  # Submodules
+  src = fetchgit {
+    url = "https://github.com/citra-emu/citra";
+    rev = "cf9bfe0690f1934847500cc5079b1aaf3299a507";
+    sha256 = "1ryc5d3fnhzlrzh1yljbq9x5n79dsb5hgqdba8z4x56iccx0kd0p";
+  };
+
+  enableParallelBuilding = true;
+  nativeBuildInputs = [ cmake ];
+  buildInputs = [ SDL2 qtbase qtmultimedia boost curl gtest ];
+  cmakeFlags = [ "-DUSE_SYSTEM_CURL=ON" "-DUSE_SYSTEM_GTEST=ON" ];
+
+  preConfigure = ''
+    # Trick configure system.
+    sed -n 's,^ *path = \(.*\),\1,p' .gitmodules | while read path; do
+      mkdir "$path/.git"
+    done
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = "https://citra-emu.org";
+    description = "An open-source emulator for the Nintendo 3DS";
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ abbradar ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/darcnes/default.nix b/nixpkgs/pkgs/misc/emulators/darcnes/default.nix
new file mode 100644
index 000000000000..70e7351e295c
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/darcnes/default.nix
@@ -0,0 +1,24 @@
+{ stdenv, fetchurl, libX11, libXt, libXext, libXaw }:
+
+stdenv.mkDerivation rec {
+  name = "darcnes-${version}";
+  version = "9b0401";
+
+  src = fetchurl {
+    url = "https://web.archive.org/web/20130511081532/http://www.dridus.com/~nyef/darcnes/download/dn${version}.tgz";
+    sha256 = "05a7mh51rg7ydb414m3p5mm05p4nz2bgvspqzwm3bhbj7zz543k3";
+  };
+
+  patches = [ ./label.patch ];
+
+  buildInputs = [ libX11 libXt libXext libXaw ];
+  installPhase = "install -Dt $out/bin darcnes";
+
+  meta = {
+    homepage = https://web.archive.org/web/20130502171725/http://www.dridus.com/~nyef/darcnes/;
+    description = "Sega Master System, Game Gear, SG-1000, NES, ColecoVision and Apple II emulator";
+    # Prohibited commercial use, credit required.
+    license = stdenv.lib.licenses.free;
+    platforms = [ "i686-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/darcnes/label.patch b/nixpkgs/pkgs/misc/emulators/darcnes/label.patch
new file mode 100644
index 000000000000..612aa1e3911e
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/darcnes/label.patch
@@ -0,0 +1,13 @@
+http://gentoo-overlays.zugaina.org/funtoo/portage/games-emulation/darcnes/files/darcnes-0401-exec-stack.patch
+
+diff -Naur old/video_x.c new/video_x.c
+--- old/video_x.c	2004-09-04 01:26:41.102187277 +0200
++++ new/video_x.c	2004-09-04 01:27:51.586427427 +0200
+@@ -366,6 +366,7 @@
+ 	}
+ 	
+     default:
++    	break;
+     }
+ }
+ 
diff --git a/nixpkgs/pkgs/misc/emulators/desmume/default.nix b/nixpkgs/pkgs/misc/emulators/desmume/default.nix
new file mode 100644
index 000000000000..d177012546e9
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/desmume/default.nix
@@ -0,0 +1,58 @@
+{ stdenv, fetchurl, fetchpatch
+, pkgconfig, libtool, intltool
+, libXmu
+, lua
+, agg, alsaLib, soundtouch, openal
+, desktop-file-utils
+, gtk2, gtkglext, libglade, pangox_compat
+, libGLU, libpcap, SDL, zziplib }:
+
+with stdenv.lib;
+stdenv.mkDerivation rec {
+
+  name = "desmume-${version}";
+  version = "0.9.11";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/project/desmume/desmume/${version}/${name}.tar.gz";
+    sha256 = "15l8wdw3q61fniy3h93d84dnm6s4pyadvh95a0j6d580rjk4pcrs";
+  };
+
+  patches = [
+    (fetchpatch {
+      name = "gcc6_fixes.patch";
+      url = "https://anonscm.debian.org/viewvc/pkg-games/packages/trunk/desmume/debian/patches/gcc6_fixes.patch?revision=15925";
+      sha256 = "0j3fmxz0mfb3f4biks03pyz8f9hy958ks6qplisl60rzq9v9qpks";
+     })
+  ];
+
+  CXXFLAGS = "-fpermissive";
+
+  buildInputs =
+  [ pkgconfig libtool intltool libXmu lua agg alsaLib soundtouch
+    openal desktop-file-utils gtk2 gtkglext libglade pangox_compat
+    libGLU libpcap SDL zziplib ];
+
+  configureFlags = [
+    "--disable-glade"  # Failing on compile step
+    "--enable-openal"
+    "--enable-glx"
+    "--enable-hud"
+    "--enable-wifi" ];
+
+  meta = {
+    description = "An open-source Nintendo DS emulator";
+    longDescription = ''
+      DeSmuME is a freeware emulator for the NDS roms & Nintendo DS
+      Lite games created by YopYop156. It supports many homebrew nds
+      rom demoes as well as a handful of Wireless Multiboot demo nds
+      roms. DeSmuME is also able to emulate nearly all of the
+      commercial nds rom titles which other DS Emulators aren't.
+    '';
+    homepage = http://www.desmume.com ;
+    license = licenses.gpl1Plus;
+    maintainers = [ maintainers.AndersonTorres ];
+    platforms = platforms.linux;
+  };
+}
+# TODO: investigate glade
diff --git a/nixpkgs/pkgs/misc/emulators/dlx/default.nix b/nixpkgs/pkgs/misc/emulators/dlx/default.nix
new file mode 100644
index 000000000000..358cc59d3db0
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/dlx/default.nix
@@ -0,0 +1,31 @@
+{ stdenv, fetchurl, unzip }:
+
+stdenv.mkDerivation {
+  name = "dlx-2012.07.08";
+
+  src = fetchurl {
+    url = "https://www.davidviner.com/zip/dlx/dlx.zip";
+    sha256 = "0q5hildq2xcig7yrqi26n7fqlanyssjirm7swy2a9icfxpppfpkn";
+  };
+
+  buildInputs = [ unzip ];
+
+  makeFlags = "LINK=gcc CFLAGS=-O2";
+
+  hardeningDisable = [ "format" ];
+
+  installPhase = ''
+    mkdir -p $out/include/dlx $out/share/dlx/{examples,doc} $out/bin
+    mv -v masm mon dasm $out/bin/
+    mv -v *.i auto.a $out/include/dlx/
+    mv -v *.a *.m $out/share/dlx/examples/
+    mv -v README.txt MANUAL.TXT $out/share/dlx/doc/
+  '';
+
+  meta = {
+    homepage = http://www.davidviner.com/dlx.php;
+    description = "DLX Simulator";
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/dolphin-emu/default.nix b/nixpkgs/pkgs/misc/emulators/dolphin-emu/default.nix
new file mode 100644
index 000000000000..392f5618b6e5
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/dolphin-emu/default.nix
@@ -0,0 +1,48 @@
+{ stdenv, pkgconfig, cmake, bluez, ffmpeg, libao, gtk2, glib, libGLU_combined
+, gettext, libpthreadstubs, libXrandr, libXext, readline, openal
+, libXdmcp, portaudio, fetchFromGitHub, libusb, libevdev
+, wxGTK30, soundtouch, miniupnpc, mbedtls, curl, lzo, sfml
+, libpulseaudio ? null }:
+
+stdenv.mkDerivation rec {
+  name = "dolphin-emu-${version}";
+  version = "5.0";
+
+  src = fetchFromGitHub {
+    owner  = "dolphin-emu";
+    repo   = "dolphin";
+    rev    = version;
+    sha256 = "07mlfnh0hwvk6xarcg315x7z2j0qbg9g7cm040df9c8psiahc3g6";
+  };
+
+  postPatch = ''
+    substituteInPlace Source/Core/VideoBackends/OGL/RasterFont.cpp \
+      --replace " CHAR_WIDTH " " CHARWIDTH "
+  '';
+
+  cmakeFlags = ''
+    -DGTK2_GLIBCONFIG_INCLUDE_DIR=${glib.out}/lib/glib-2.0/include
+    -DGTK2_GDKCONFIG_INCLUDE_DIR=${gtk2.out}/lib/gtk-2.0/include
+    -DGTK2_INCLUDE_DIRS=${gtk2.dev}/include/gtk-2.0
+    -DENABLE_LTO=True
+  '';
+
+  enableParallelBuilding = true;
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ cmake bluez ffmpeg libao libGLU_combined gtk2 glib
+                  gettext libpthreadstubs libXrandr libXext readline openal
+                  libevdev libXdmcp portaudio libusb libpulseaudio
+                  libevdev libXdmcp portaudio libusb libpulseaudio
+                  wxGTK30 soundtouch miniupnpc mbedtls curl lzo sfml ];
+
+  meta = {
+    homepage = https://dolphin-emu.org/;
+    description = "Gamecube/Wii/Triforce emulator for x86_64 and ARMv8";
+    license = stdenv.lib.licenses.gpl2Plus;
+    maintainers = with stdenv.lib.maintainers; [ MP2E ];
+    # x86_32 is an unsupported platform.
+    # Enable generic build if you really want a JIT-less binary.
+    platforms = [ "x86_64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/dolphin-emu/master.nix b/nixpkgs/pkgs/misc/emulators/dolphin-emu/master.nix
new file mode 100644
index 000000000000..68176ff427e3
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/dolphin-emu/master.nix
@@ -0,0 +1,84 @@
+{ stdenv, fetchFromGitHub, makeWrapper, makeDesktopItem, pkgconfig, cmake, qt5
+, bluez, ffmpeg, libao, libGLU_combined, pcre, gettext, libXrandr, libusb, lzo
+, libpthreadstubs, libXext, libXxf86vm, libXinerama, libSM, libXdmcp, readline
+, openal, udev, libevdev, portaudio, curl, alsaLib, miniupnpc, enet, mbedtls
+, soundtouch, sfml, vulkan-loader ? null, libpulseaudio ? null
+
+# - Inputs used for Darwin
+, CoreBluetooth, cf-private, ForceFeedback, IOKit, OpenGL, libpng, hidapi }:
+
+let
+  desktopItem = makeDesktopItem {
+    name = "dolphin-emu-master";
+    exec = "dolphin-emu-master";
+    icon = "dolphin-emu";
+    comment = "A Wii/GameCube Emulator";
+    desktopName = "Dolphin Emulator (master)";
+    genericName = "Wii/GameCube Emulator";
+    categories = "Game;Emulator;";
+    startupNotify = "false";
+  };
+in stdenv.mkDerivation rec {
+  name = "dolphin-emu-${version}";
+  version = "2018-09-24";
+
+  src = fetchFromGitHub {
+    owner = "dolphin-emu";
+    repo = "dolphin";
+    rev = "97b1a9bb2a0c29f0f68963483156d5285e1fb1d5";
+    sha256 = "0dwc4l7a7r1f65gh1rhxa854xsknrgp62rr3a0y67lk3xf5y38d7";
+  };
+
+  enableParallelBuilding = true;
+  nativeBuildInputs = [ cmake pkgconfig ]
+  ++ stdenv.lib.optionals stdenv.isLinux [ makeWrapper ];
+
+  buildInputs = [
+    curl ffmpeg libao libGLU_combined pcre gettext libpthreadstubs libpulseaudio
+    libXrandr libXext libXxf86vm libXinerama libSM readline openal libXdmcp lzo
+    portaudio libusb libpng hidapi miniupnpc enet mbedtls soundtouch sfml
+    qt5.qtbase
+  ] ++ stdenv.lib.optionals stdenv.isLinux [
+    bluez udev libevdev alsaLib vulkan-loader
+  ] ++ stdenv.lib.optionals stdenv.isDarwin [
+    CoreBluetooth cf-private OpenGL ForceFeedback IOKit
+  ];
+
+  cmakeFlags = [
+    "-DUSE_SHARED_ENET=ON"
+    "-DENABLE_LTO=ON"
+  ] ++ stdenv.lib.optionals stdenv.isDarwin [
+    "-DOSX_USE_DEFAULT_SEARCH_PATH=True"
+  ];
+
+  # - Allow Dolphin to use nix-provided libraries instead of building them
+  preConfigure = ''
+    sed -i -e 's,DISTRIBUTOR "None",DISTRIBUTOR "NixOS",g' CMakeLists.txt
+  '' + stdenv.lib.optionalString stdenv.isDarwin ''
+    sed -i -e 's,if(NOT APPLE),if(true),g' CMakeLists.txt
+    sed -i -e 's,if(LIBUSB_FOUND AND NOT APPLE),if(LIBUSB_FOUND),g' \
+      CMakeLists.txt
+  '';
+
+  postInstall = ''
+    cp -r ${desktopItem}/share/applications $out/share
+    ln -sf $out/bin/dolphin-emu $out/bin/dolphin-emu-master
+  '' + stdenv.lib.optionalString stdenv.isLinux ''
+    wrapProgram $out/bin/dolphin-emu-nogui \
+      --prefix LD_LIBRARY_PATH : ${vulkan-loader}/lib
+    wrapProgram $out/bin/dolphin-emu \
+      --prefix LD_LIBRARY_PATH : ${vulkan-loader}/lib
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = "https://dolphin-emu.org";
+    description = "Gamecube/Wii/Triforce emulator for x86_64 and ARMv8";
+    license = licenses.gpl2Plus;
+    maintainers = with maintainers; [ MP2E ];
+    branch = "master";
+    # x86_32 is an unsupported platform.
+    # Enable generic build if you really want a JIT-less binary.
+    broken = stdenv.isDarwin;
+    platforms = [ "x86_64-linux" "x86_64-darwin" ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/dosbox/default.nix b/nixpkgs/pkgs/misc/emulators/dosbox/default.nix
new file mode 100644
index 000000000000..878e98fa1665
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/dosbox/default.nix
@@ -0,0 +1,40 @@
+{ stdenv, lib, fetchurl, makeDesktopItem, SDL, SDL_net, SDL_sound, libGLU_combined, libpng }:
+
+stdenv.mkDerivation rec {
+  name = "dosbox-0.74-2";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/dosbox/${name}.tar.gz";
+    sha256 = "1ksp1b5szi0vy4x55rm3j1y9wq5mlslpy8llpg87rpdyjlsk0xvh";
+  };
+
+  hardeningDisable = [ "format" ];
+
+  buildInputs = [ SDL SDL_net SDL_sound libGLU_combined libpng ];
+
+  configureFlags = lib.optional stdenv.isDarwin "--disable-sdltest";
+
+  desktopItem = makeDesktopItem {
+    name = "dosbox";
+    exec = "dosbox";
+    comment = "x86 emulator with internal DOS";
+    desktopName = "DOSBox";
+    genericName = "DOS emulator";
+    categories = "Application;Emulator;";
+  };
+
+  postInstall = ''
+     mkdir -p $out/share/applications
+     cp ${desktopItem}/share/applications/* $out/share/applications
+  '';
+
+  enableParallelBuilding = true;
+
+  meta = with lib; {
+    homepage = http://www.dosbox.com/;
+    description = "A DOS emulator";
+    platforms = platforms.unix;
+    maintainers = with maintainers; [ matthewbauer ];
+    license = licenses.gpl2;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/emulationstation/default.nix b/nixpkgs/pkgs/misc/emulators/emulationstation/default.nix
new file mode 100644
index 000000000000..9dec1ecacae0
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/emulationstation/default.nix
@@ -0,0 +1,30 @@
+{ stdenv, fetchFromGitHub, pkgconfig, cmake, curl, boost, eigen
+, freeimage, freetype, libGLU_combined, SDL2, alsaLib, libarchive }:
+
+stdenv.mkDerivation rec {
+  name = "emulationstation-${version}";
+  version = "2.0.1a";
+
+  src = fetchFromGitHub {
+    owner = "Aloshi";
+    repo = "EmulationStation";
+    rev = "646bede3d9ec0acf0ae378415edac136774a66c5";
+    sha256 = "0cm0sq2wri2l9cvab1l0g02za59q7klj0h3p028vr96n6njj4w9v";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ cmake alsaLib boost curl eigen freeimage freetype libarchive libGLU_combined SDL2 ];
+
+  buildPhase = "cmake . && make";
+  installPhase = ''
+    install -D ../emulationstation $out/bin/emulationstation
+  '';
+
+  meta = {
+    description = "A flexible emulator front-end supporting keyboardless navigation and custom system themes";
+    homepage = https://emulationstation.org;
+    maintainers = [ stdenv.lib.maintainers.edwtjo ];
+    license = stdenv.lib.licenses.mit;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/epsxe/default.nix b/nixpkgs/pkgs/misc/emulators/epsxe/default.nix
new file mode 100644
index 000000000000..5fee8b4b83d4
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/epsxe/default.nix
@@ -0,0 +1,56 @@
+{ stdenv, fetchurl, alsaLib, curl, gdk_pixbuf, glib, gtk3, libGLU_combined,
+  libX11, openssl, ncurses5, SDL, SDL_ttf, unzip, zlib, wrapGAppsHook }:
+
+with stdenv.lib;
+
+stdenv.mkDerivation rec {
+  name = "epsxe-${version}";
+  version = "2.0.5";
+
+  src = let
+    version2 = concatStrings (splitString "." version);
+    platform = "linux" + (optionalString stdenv.is64bit "_x64");
+  in fetchurl {
+    url = "https://www.epsxe.com/files/ePSXe${version2}${platform}.zip";
+    sha256 = if stdenv.is64bit
+             then "16fa9qc2xhaz1f6294m0b56s5l86cbmclwm9w3mqnch0yjsrvab0"
+             else "1677lclam557kp8jwvchdrk27zfj50fqx2q9i3bcx26d9k61q3kl";
+  };
+
+  nativeBuildInputs = [ unzip wrapGAppsHook ];
+  sourceRoot = ".";
+
+  buildInputs = [
+    alsaLib
+    curl
+    gdk_pixbuf
+    glib
+    gtk3
+    libX11
+    libGLU_combined
+    openssl
+    ncurses5
+    SDL
+    SDL_ttf
+    stdenv.cc.cc.lib
+    zlib
+  ];
+
+  dontStrip = true;
+
+  installPhase = ''
+    install -D ${if stdenv.is64bit then "epsxe_x64" else "ePSXe"} $out/bin/epsxe
+    patchelf \
+      --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) \
+      --set-rpath ${makeLibraryPath buildInputs} \
+      $out/bin/epsxe
+  '';
+
+  meta = {
+    homepage = http://epsxe.com/;
+    description = "Enhanced PSX (PlayStation 1) emulator";
+    license = licenses.unfree;
+    maintainers = with maintainers; [ yegortimoshenko ];
+    platforms = [ "i686-linux" "x86_64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/fakenes/build.patch b/nixpkgs/pkgs/misc/emulators/fakenes/build.patch
new file mode 100644
index 000000000000..90799d977a14
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/fakenes/build.patch
@@ -0,0 +1,84 @@
+diff --git a/build/openal.cbd b/build/openal.cbd
+index d18e62d..74af061 100644
+--- a/build/openal.cbd
++++ b/build/openal.cbd
+@@ -23,7 +23,7 @@ CFLAGS += ' -DUSE_OPENAL'
+ # --
+ 
+ do ifplat unix
+-   LDFLAGS += ' `openal-config --libs`'
++   LDFLAGS += ' -lopenal'
+ else
+    LDFLAGS += ' -lOpenAL32'
+ done
+diff --git a/build/alleggl.cbd b/build/alleggl.cbd
+index e2708ff..e826371 100644
+--- a/build/alleggl.cbd
++++ b/build/alleggl.cbd
+@@ -22,7 +22,7 @@ CFLAGS += ' -DUSE_ALLEGROGL'
+ 
+ # --
+ 
+-LIBAGL = agl
++LIBAGL = alleggl
+ 
+ ifopt debug LIBAGL = 'agld'
+
+diff --git a/src/apu.cpp b/src/apu.cpp
+index af59f1c..893a798 100644
+--- a/src/apu.cpp
++++ b/src/apu.cpp
+@@ -1930,7 +1930,7 @@ static void amplify(real& sample)
+          gain -= releaseRate;
+       }
+ 
+-      real output = (1.0 / max(gain, EPSILON));
++      real output = (1.0 / MAX(gain, EPSILON));
+       output = fixf(output, apu_agc_gain_floor, apu_agc_gain_ceiling);
+       sample *= output;
+    }
+diff --git a/src/audio.cpp b/src/audio.cpp
+index b9650dc..c21c05e 100644
+--- a/src/audio.cpp
++++ b/src/audio.cpp
+@@ -7,6 +7,7 @@
+    You must read and accept the license prior to use. */
+ 
+ #include <allegro.h>
++#include <cstdio>
+ #include <cstdlib>
+ #include <cstring>
+ #include <vector>
+@@ -234,7 +235,7 @@ void audio_update(void)
+          const unsigned queuedFrames = (audioQueue.size() / audio_channels);
+          if(queuedFrames > 0) {
+             // Determine how many frames we want to make room for.
+-            const unsigned framesToAdd = min(queuedFrames, audio_buffer_size_frames);
++            const unsigned framesToAdd = MIN(queuedFrames, audio_buffer_size_frames);
+             // Make room for the frames in the buffer.
+             const unsigned framesToMove = (audioBufferedFrames - framesToAdd);
+             if(framesToMove > 0) {
+@@ -258,7 +259,7 @@ void audio_update(void)
+          // Determine how many frames are available in the buffer.
+          const unsigned bufferableFrames = (audio_buffer_size_frames - audioBufferedFrames);
+          // Determine the number of frames to copy to the buffer.
+-         const unsigned framesToCopy = min(queuedFrames, bufferableFrames);
++         const unsigned framesToCopy = MIN(queuedFrames, bufferableFrames);
+ 
+          // Copy frames to the buffer.
+          for(unsigned frame = 0; frame < framesToCopy; frame++) {
+diff --git a/src/include/common.h b/src/include/common.h
+index be28795..e2d21d1 100644
+--- a/src/include/common.h
++++ b/src/include/common.h
+@@ -41,8 +41,10 @@ extern "C" {
+ #define true   TRUE
+ #define false  FALSE
+ 
++/*
+ #define min(x,y)   MIN((x),(y))
+ #define max(x,y)   MAX((x),(y))
++*/
+ 
+ #define true_or_false(x)   ((x) ? true : false)
+ 
diff --git a/nixpkgs/pkgs/misc/emulators/fakenes/default.nix b/nixpkgs/pkgs/misc/emulators/fakenes/default.nix
new file mode 100644
index 000000000000..eb7964cc017d
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/fakenes/default.nix
@@ -0,0 +1,32 @@
+{stdenv, fetchurl, allegro, openal, libGLU_combined, zlib, hawknl, freeglut, libX11,
+  libXxf86vm, libXcursor, libXpm }:
+
+stdenv.mkDerivation {
+  name = "fakenes-0.5.9b3";
+  src = fetchurl {
+    url = mirror://sourceforge/fakenes/fakenes-0.5.9-beta3.tar.gz;
+    sha256 = "026h67s4pzc1vma59pmzk02iy379255qbai2q74wln9bxqcpniy4";
+  };
+
+  buildInputs = [ allegro openal libGLU_combined zlib hawknl freeglut libX11
+    libXxf86vm libXcursor libXpm ];
+
+  hardeningDisable = [ "format" ];
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp fakenes $out/bin
+  '';
+
+  NIX_LDFLAGS = "-lX11 -lXxf86vm -lXcursor -lXpm";
+
+  patches = [ ./build.patch ];
+
+  meta = {
+    homepage = http://fakenes.sourceforge.net/;
+    license = stdenv.lib.licenses.gpl2Plus;
+    description = "Portable Open Source NES Emulator";
+    platforms = stdenv.lib.platforms.linux;
+    broken = true;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/fceux/default.nix b/nixpkgs/pkgs/misc/emulators/fceux/default.nix
new file mode 100644
index 000000000000..13ebeb1d2a96
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/fceux/default.nix
@@ -0,0 +1,36 @@
+{stdenv, fetchurl, scons, zlib, SDL, lua5_1, pkgconfig}:
+
+stdenv.mkDerivation {
+  name = "fceux-2.2.3";
+
+  src = fetchurl {
+    url = mirror://sourceforge/fceultra/Source%20Code/2.2.3%20src/fceux-2.2.3.src.tar.gz;
+    sha256 = "0gl2i3qdmcm7v9m5kpfz98w05d8m33990jiwka043ya7lflxvrjb";
+  };
+
+  nativeBuildInputs = [ pkgconfig scons ];
+  buildInputs = [
+    zlib SDL lua5_1
+  ];
+
+  sconsFlags = "OPENGL=false GTK=false CREATE_AVI=false LOGO=false";
+  prefixKey = "--prefix=";
+
+  # sed allows scons to find libraries in nix.
+  # mkdir is a hack to make scons succeed.  It still doesn't
+  # actually put the files in there due to a bug in the SConstruct file.
+  # OPENGL doesn't work because fceux dlopens the library.
+  preBuild = ''
+    sed -e 's/env *= *Environment *.*/&; env['"'"'ENV'"'"']=os.environ;/' -i SConstruct
+    export CC="gcc"
+    export CXX="g++"
+    mkdir -p "$out" "$out/share/applications" "$out/share/pixmaps"
+  '';
+
+  meta = {
+    description = "A Nintendo Entertainment System (NES) Emulator";
+    license = stdenv.lib.licenses.gpl2;
+    homepage = http://www.fceux.com/;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/firebird-emu/default.nix b/nixpkgs/pkgs/misc/emulators/firebird-emu/default.nix
new file mode 100644
index 000000000000..882bf13f4eaf
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/firebird-emu/default.nix
@@ -0,0 +1,38 @@
+{ stdenv, fetchFromGitHub, qmake, qtbase, qtdeclarative }:
+
+stdenv.mkDerivation rec {
+  name = "firebird-emu-${version}";
+  version = "1.4";
+
+  src = fetchFromGitHub {
+    owner = "nspire-emus";
+    repo = "firebird";
+    rev = "v${version}";
+    sha256 = "0pdca6bgnmzfgf5kp83as99y348gn4plzbxnqxjs61vp489baahq";
+    fetchSubmodules = true;
+  };
+
+  enableParallelBuilding = true;
+
+  nativeBuildInputs = [ qmake ];
+
+  buildInputs = [ qtbase qtdeclarative ];
+
+  makeFlags = [ "INSTALL_ROOT=$(out)" ];
+
+  # Attempts to install to /usr/bin and /usr/share/applications, which Nix does
+  # not use.
+  prePatch = ''
+    substituteInPlace firebird.pro \
+      --replace '/usr/' '/'
+  '';
+
+  meta = {
+    homepage = https://github.com/nspire-emus/firebird;
+    description = "Third-party multi-platform emulator of the ARM-based TI-Nspireâ„¢ calculators";
+    license = stdenv.lib.licenses.gpl3;
+    maintainers = with stdenv.lib.maintainers; [ pneumaticat ];
+    # Only tested on Linux, but likely possible to build on, e.g. macOS
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/fs-uae/default.nix b/nixpkgs/pkgs/misc/emulators/fs-uae/default.nix
new file mode 100644
index 000000000000..9856c93eda2d
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/fs-uae/default.nix
@@ -0,0 +1,32 @@
+{ stdenv, fetchurl, pkgconfig
+, gettext, gtk2, SDL2, zlib, glib, openal, libGLU_combined, lua, freetype, libmpeg2, zip }:
+
+with stdenv.lib;
+stdenv.mkDerivation rec {
+
+  name = "fs-uae-${version}";
+  version = "2.8.4";
+
+  src = fetchurl {
+    url = "https://fs-uae.net/fs-uae/stable/${version}/${name}.tar.gz";
+    sha256 = "19ccb3gbpjwwazqc9pyin3jicjl27m2gyvy5bb5zysq0mxpzassj";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ gettext gtk2 SDL2 zlib glib openal libGLU_combined lua freetype libmpeg2 zip ];
+
+  meta = {
+    description = "An accurate, customizable Amiga Emulator";
+    longDescription = ''
+      FS-UAE integrates the most accurate Amiga emulation code available
+      from WinUAE. FS-UAE emulates A500, A500+, A600, A1200, A1000, A3000
+      and A4000 models, but you can tweak the hardware configuration and
+      create customized Amigas.
+    '';
+    license = licenses.gpl2Plus;
+    homepage = https://fs-uae.net;
+    maintainers = with stdenv.lib; [ maintainers.AndersonTorres ];
+    platforms = [ "i686-linux" "x86_64-linux" ];
+  };
+}
+# TODO: testing and Python GUI support
diff --git a/nixpkgs/pkgs/misc/emulators/gens-gs/default.nix b/nixpkgs/pkgs/misc/emulators/gens-gs/default.nix
new file mode 100644
index 000000000000..418d6440b694
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/gens-gs/default.nix
@@ -0,0 +1,25 @@
+{ stdenv, fetchurl, pkgconfig, gtk2, SDL, nasm, zlib, libpng, libGLU_combined }:
+
+stdenv.mkDerivation {
+  name = "gens-gs-7";
+
+  src = fetchurl {
+    url = http://retrocdn.net/images/6/6d/Gens-gs-r7.tar.gz;
+    sha256 = "1ha5s6d3y7s9aq9f4zmn9p88109c3mrj36z2w68jhiw5xrxws833";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ gtk2 SDL nasm zlib libpng libGLU_combined ];
+
+  # Work around build failures on recent GTK+.
+  # See http://ubuntuforums.org/showthread.php?p=10535837
+  NIX_CFLAGS_COMPILE = "-UGTK_DISABLE_DEPRECATED -UGSEAL_ENABLE";
+
+  meta = with stdenv.lib; {
+    homepage = https://segaretro.org/Gens/GS;
+    description = "A Genesis/Mega Drive emulator";
+    platforms = [ "i686-linux" ];
+    license = licenses.gpl2Plus;
+    maintainers = [ maintainers.eelco ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/gxemul/default.nix b/nixpkgs/pkgs/misc/emulators/gxemul/default.nix
new file mode 100644
index 000000000000..ea2d6bbfecc8
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/gxemul/default.nix
@@ -0,0 +1,37 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "gxemul-${version}";
+  version = "0.6.0.1";
+
+  src = fetchurl {
+    url = "http://gxemul.sourceforge.net/src/${name}.tar.gz";
+    sha256 = "1afd9l0igyv7qgc0pn3rkdgrl5d0ywlyib0qhg4li23zilyq5407";
+  };
+
+  configurePhase = "./configure";
+
+  installPhase = ''
+    mkdir -p $out/bin;
+    mkdir -p $out/share/${name};
+    cp gxemul $out/bin;
+    cp -r doc $out/share/${name};
+    cp -r demos $out/share/${name};
+    cp -r ./man $out/;
+  '';
+
+  meta = {
+    license = stdenv.lib.licenses.bsd3;
+    description = "Gavare's experimental emulator";
+    longDescription = ''
+      GXemul is a framework for full-system computer architecture
+      emulation. Several real machines have been implemented within the
+      framework, consisting of processors (ARM, MIPS, Motorola 88K,
+      PowerPC, and SuperH) and surrounding hardware components such as
+      framebuffers, interrupt controllers, busses, disk controllers,
+      and serial controllers. The emulation is working well enough to
+      allow several unmodified "guest" operating systems to run.
+    '';
+    homepage = http://gxemul.sourceforge.net/;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/hatari/default.nix b/nixpkgs/pkgs/misc/emulators/hatari/default.nix
new file mode 100644
index 000000000000..287df4db01be
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/hatari/default.nix
@@ -0,0 +1,23 @@
+{ stdenv, fetchurl, zlib, SDL, cmake }:
+
+stdenv.mkDerivation rec {
+  name = "hatari-2.1.0";
+
+  src = fetchurl {
+    url = "https://download.tuxfamily.org/hatari/2.1.0/${name}.tar.bz2";
+    sha256 = "0909l9fq20ninf8xgv5qf0a5y64cpk5ja1rsk2iaid1dx5h98agb";
+  };
+
+  # For pthread_cancel
+  cmakeFlags = "-DCMAKE_EXE_LINKER_FLAGS=-lgcc_s";
+
+  buildInputs = [ zlib SDL cmake ];
+
+  meta = {
+    homepage = http://hatari.tuxfamily.org/;
+    description = "Atari ST/STE/TT/Falcon emulator";
+    license = stdenv.lib.licenses.gpl2Plus;
+    platforms = stdenv.lib.platforms.linux;
+    maintainers = with stdenv.lib.maintainers; [ fuuzetsu ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/higan/0001-change-flags.diff b/nixpkgs/pkgs/misc/emulators/higan/0001-change-flags.diff
new file mode 100644
index 000000000000..5821a9c130b0
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/higan/0001-change-flags.diff
@@ -0,0 +1,26 @@
+diff -Naur higan_v105-source.old/higan/GNUmakefile higan_v105-source.new/higan/GNUmakefile
+--- higan_v105-source.old/higan/GNUmakefile	2017-10-07 01:34:22.000000000 -0300
++++ higan_v105-source.new/higan/GNUmakefile	2017-10-17 00:02:40.580957396 -0200
+@@ -26,7 +26,7 @@
+   flags += -fopenmp
+   link += -fopenmp
+   ifeq ($(binary),application)
+-    flags += -march=native
++    flags +=
+     link += -Wl,-export-dynamic
+     link += -lX11 -lXext
+   else ifeq ($(binary),library)
+diff -Naur higan_v105-source.old/nall/GNUmakefile higan_v105-source.new/nall/GNUmakefile
+--- higan_v105-source.old/nall/GNUmakefile	2017-09-23 18:34:22.000000000 -0300
++++ higan_v105-source.new/nall/GNUmakefile	2017-10-17 00:03:33.568916550 -0200
+@@ -40,8 +40,8 @@
+ objcflags := -x objective-c -std=c11
+ cppflags := -x c++ -std=c++14
+ objcppflags := -x objective-c++ -std=c++14
+-flags :=
+-link :=
++flags := $(CXXFLAGS)
++link := $(LDFLAGS)
+ 
+ # compiler detection
+ ifeq ($(compiler),)
diff --git a/nixpkgs/pkgs/misc/emulators/higan/default.nix b/nixpkgs/pkgs/misc/emulators/higan/default.nix
new file mode 100644
index 000000000000..45b2f79146c1
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/higan/default.nix
@@ -0,0 +1,84 @@
+{ stdenv, fetchurl
+, p7zip, pkgconfig
+, libX11, libXv
+, udev
+, libGLU_combined, SDL
+, libao, openal, libpulseaudio
+, gtk2, gtksourceview }:
+
+with stdenv.lib;
+stdenv.mkDerivation rec {
+
+  name = "higan-${version}";
+  version = "106";
+  sourceName = "higan_v${version}-source";
+
+  src = fetchurl {
+    urls = [ "https://download.byuu.org/${sourceName}.7z" ];
+    sha256 = "063dzp9wrdnbvagraxi31xg0154y2gf67rrd0mnc8h104cgzjr35";
+    curlOpts = "--user-agent 'Mozilla/5.0'"; # the good old user-agent trick...
+  };
+
+  patches = [ ./0001-change-flags.diff ];
+  postPatch = "sed '1i#include <cmath>' -i higan/fc/ppu/ppu.cpp";
+
+  buildInputs =
+  [ p7zip pkgconfig libX11 libXv udev libGLU_combined
+    SDL libao openal libpulseaudio gtk2 gtksourceview ];
+
+  unpackPhase = ''
+    7z x $src
+    sourceRoot=${sourceName}
+  '';
+
+  buildPhase = ''
+    make compiler=c++ -C icarus
+    make compiler=c++ -C higan
+  '';
+
+  # Now the cheats file will be distributed separately
+  installPhase = ''
+    install -dm 755 $out/bin $out/share/applications $out/share/higan $out/share/pixmaps
+    install -m 755 icarus/out/icarus $out/bin/
+    install -m 755 higan/out/higan $out/bin/
+    install -m 644 higan/data/higan.desktop $out/share/applications/
+    install -m 644 higan/data/higan.png $out/share/pixmaps/higan-icon.png
+    install -m 644 higan/resource/logo/higan.png $out/share/pixmaps/higan-logo.png
+    cp --recursive --no-dereference --preserve='links' --no-preserve='ownership' \
+      higan/systems/* $out/share/higan/
+  '';
+
+  fixupPhase = ''
+    # A dirty workaround, suggested by @cpages:
+    # we create a first-run script to populate
+    # the local $HOME with all the auxiliary
+    # stuff needed by higan at runtime
+
+    cat <<EOF > $out/bin/higan-init.sh
+    #!${stdenv.shell}
+
+    cp --recursive --update $out/share/higan/*.sys \$HOME/.local/share/higan/
+
+    EOF
+
+    chmod +x $out/bin/higan-init.sh
+  '';
+
+  meta = {
+    description = "An open-source, cycle-accurate Nintendo multi-system emulator";
+    longDescription = ''
+      higan (formerly bsnes) is a multi-system game console emulator.
+      It currently supports the following systems:
+        - Nintendo's Famicom, Super Famicom (with subsystems: 
+          Super Game Boy, BS-X Satellaview, Sufami Turbo); 
+          Game Boy, Game Boy Color, Game Boy Advance;
+        - Sega's Master System, Game Gear, Mega Drive;
+        - NEC's PC Engine, SuperGrafx;
+        - Bandai's WonderSwan, WonderSwan Color.
+    '';
+    homepage = https://byuu.org/emulation/higan/;
+    license = licenses.gpl3Plus;
+    maintainers = with maintainers; [ AndersonTorres ];
+    platforms = with platforms; unix;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/kega-fusion/default.nix b/nixpkgs/pkgs/misc/emulators/kega-fusion/default.nix
new file mode 100644
index 000000000000..bdc372c7ca23
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/kega-fusion/default.nix
@@ -0,0 +1,78 @@
+{ stdenv, lib, writeText, fetchurl, upx, libGLU, glib, gtk2, alsaLib, libSM, libX11, gdk_pixbuf, pango, libXinerama, mpg123 }:
+
+let
+  libPath = lib.makeLibraryPath [ stdenv.cc.cc libGLU glib gtk2 alsaLib libSM libX11 gdk_pixbuf pango libXinerama ];
+
+in stdenv.mkDerivation rec {
+  name = "kega-fusion-${version}";
+  version = "3.63x";
+
+  src = fetchurl {
+    url = "http://www.carpeludum.com/download/Fusion363x.tar.gz";
+    sha256 = "14s6czy20h5khyy7q95hd7k77v17ssafv9l6lafkiysvj2nmw94g";
+  };
+
+  plugins = fetchurl {
+    url = "http://www.carpeludum.com/download/PluginsLinux.tar.gz";
+    sha256 = "0d623cvh6n5ijj3wb64g93mxx2xbichsn7hj7brbb0ndw5cs70qj";
+  };
+
+  runner = writeText "kega-fusion" ''
+    #!${stdenv.shell} -ex
+
+    kega_libdir="@out@/lib/kega-fusion"
+    kega_localdir="$HOME/.Kega Fusion"
+
+    # create local plugins directory if not present
+    mkdir -p "$kega_localdir/Plugins"
+
+    # create links for every included plugin
+    if [ $(ls -1A $kega_libdir/plugins | wc -l) -gt 0 ]; then
+      for i in $kega_libdir/plugins/*; do
+        if [ ! -e "$kega_localdir/Plugins/$(basename "$i")" ]; then
+          ln -sf "$i" "$kega_localdir/Plugins/"
+        fi
+      done
+    fi
+
+    # copy configuration file if not present
+    if ! [ -f "$kega_localdir/Fusion.ini" ]; then
+      cat > "$kega_localdir/Fusion.ini" <<EOF
+    ALSADeviceName=default
+    libmpg123path=${lib.getLib mpg123}/lib/libmpg123.so.0
+    EOF
+    else
+      sed -i 's,^\(libmpg123path=\).*,\1${lib.getLib mpg123}/lib/libmpg123.so.0,' "$kega_localdir/Fusion.ini"
+    fi
+
+    # here we go!
+    exec "$kega_libdir/Fusion" "$@"
+  '';
+
+  dontStrip = true;
+  dontPatchELF = true;
+
+  nativeBuildInputs = [ upx ];
+
+  installPhase = ''
+    upx -d Fusion
+    install -Dm755 Fusion "$out/lib/kega-fusion/Fusion"
+    patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" --set-rpath "${libPath}" "$out/lib/kega-fusion/Fusion"
+
+    tar -xaf $plugins
+    mkdir -p "$out/lib/kega-fusion/plugins"
+    cp -r Plugins/*.rpi "$out/lib/kega-fusion/plugins"
+
+    mkdir -p "$out/bin"
+    substitute "$runner" "$out/bin/kega-fusion" --subst-var out
+    chmod +x "$out/bin/kega-fusion"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Sega SG1000, SC3000, SF7000, Master System, Game Gear, Genesis/Megadrive, SVP, Pico, SegaCD/MegaCD and 32X emulator";
+    homepage = http://www.carpeludum.com/kega-fusion/;
+    maintainers = with maintainers; [ abbradar ];
+    license = licenses.unfreeRedistributable;
+    platforms = [ "i686-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/libdsk/default.nix b/nixpkgs/pkgs/misc/emulators/libdsk/default.nix
new file mode 100644
index 000000000000..9a99c6ddb6f9
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/libdsk/default.nix
@@ -0,0 +1,19 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "libdsk-${version}";
+  version = "1.5.8";
+
+  src = fetchurl {
+    url = "https://www.seasip.info/Unix/LibDsk/${name}.tar.gz";
+    sha256 = "1fdypk6gjkb4i2ghnbn3va50y69pdym51jx3iz9jns4636z4sfqd";
+  };
+
+  meta = with stdenv.lib; {
+    description = "A library for accessing discs and disc image files";
+    homepage = http://www.seasip.info/Unix/LibDsk/;
+    license = licenses.gpl2Plus;
+    maintainers = [ maintainers.genesis ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/mednafen/default.nix b/nixpkgs/pkgs/misc/emulators/mednafen/default.nix
new file mode 100644
index 000000000000..9101c1587c25
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/mednafen/default.nix
@@ -0,0 +1,42 @@
+{ stdenv, fetchurl, pkgconfig, freeglut, libGLU_combined, libcdio, libjack2
+, libsamplerate, libsndfile, libX11, SDL, SDL_net, zlib }:
+
+stdenv.mkDerivation rec {
+  name = "mednafen-${version}";
+  version = "0.9.48";
+
+  src = fetchurl {
+    url = "https://mednafen.github.io/releases/files/${name}.tar.xz";
+    sha256 = "00i12mywhp43274aq466fwavglk5b7d8z8bfdna12ra9iy1hrk6k";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+
+  buildInputs = [
+    freeglut
+    libGLU_combined
+    libcdio
+    libjack2
+    libsamplerate
+    libsndfile
+    libX11
+    SDL
+    SDL_net
+    zlib
+  ];
+
+  hardeningDisable = [ "pic" ];
+
+  postInstall = ''
+    mkdir -p $out/share/doc
+    mv Documentation $out/share/doc/mednafen
+  '';
+
+  meta = with stdenv.lib; {
+    description = "A portable, CLI-driven, SDL+OpenGL-based, multi-system emulator";
+    homepage = https://mednafen.github.io/;
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ AndersonTorres ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/mednafen/server.nix b/nixpkgs/pkgs/misc/emulators/mednafen/server.nix
new file mode 100644
index 000000000000..75eeeea4c008
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/mednafen/server.nix
@@ -0,0 +1,21 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "mednafen-server-${version}";
+  version = "0.5.2";
+
+  src = fetchurl {
+    url = "https://mednafen.github.io/releases/files/mednafen-server-${version}.tar.xz";
+    sha256 = "0xm7dj5nwnrsv69r72rcnlw03jm0l8rmrg3s05gjfvxyqmlb36dq";
+  };
+
+  postInstall = "install -m 644 -Dt $out/share/mednafen-server standard.conf";
+
+  meta = with stdenv.lib; {
+    description = "Netplay server for Mednafen";
+    homepage = https://mednafen.github.io/;
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ AndersonTorres ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/mednaffe/default.nix b/nixpkgs/pkgs/misc/emulators/mednaffe/default.nix
new file mode 100644
index 000000000000..c62d9c90ca79
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/mednaffe/default.nix
@@ -0,0 +1,30 @@
+{ stdenv, fetchFromGitHub, makeWrapper, autoreconfHook, pkgconfig, wrapGAppsHook
+, gtk2 ? null, gtk3 ? null, mednafen }:
+
+with stdenv.lib;
+
+stdenv.mkDerivation rec {
+  name = "mednaffe-${version}";
+  version = "0.8.6";
+
+  src = fetchFromGitHub {
+    owner = "AmatCoder";
+    repo = "mednaffe";
+    rev = "v${version}";
+    sha256 = "13l7gls430dcslpan39k0ymdnib2v6crdsmn6bs9k9g30nfnqi6m";
+  };
+
+  nativeBuildInputs = [ autoreconfHook makeWrapper pkgconfig wrapGAppsHook ];
+  buildInputs = [ gtk2 gtk3 mednafen ];
+
+  configureFlags = [ (enableFeature (gtk3 != null) "gtk3") ];
+  postInstall = "wrapProgram $out/bin/mednaffe --set PATH ${mednafen}/bin";
+
+  meta = {
+    description = "GTK-based frontend for mednafen emulator";
+    homepage = https://github.com/AmatCoder/mednaffe;
+    license = licenses.gpl3Plus;
+    maintainers = with maintainers; [ sheenobu yegortimoshenko ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/mess/default.nix b/nixpkgs/pkgs/misc/emulators/mess/default.nix
new file mode 100644
index 000000000000..65867de61a23
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/mess/default.nix
@@ -0,0 +1,49 @@
+{ stdenv, fetchurl, unzip, pkgconfig, SDL, gtk2, GConf, libGLU_combined
+, expat, zlib }:
+
+let
+
+  version = "139";
+
+  mameSrc = fetchurl {
+    url = "https://github.com/mamedev/mame/releases/download/mame0139/mame0${version}s.zip";
+    sha256 = "1mpkwxfz38cgxzvlni2y3fxas3b8qmnzj2ik2zzbd8mr622jdp79";
+  };
+
+  messSrc = fetchurl {
+    url = "http://www.progettosnaps.net/MESS/src/mess0${version}s.zip";
+    name = "mess0139s.zip";
+    sha256 = "1v892cg6wn8cdwc8pf1gcqqdb1v1v295r6jw2hf58svwx3h27xyy";
+  };
+
+in
+
+stdenv.mkDerivation { 
+  name = "mess-0.${version}";
+
+  unpackPhase =
+    ''
+      unzip ${mameSrc}
+      # Yes, the MAME distribution is a zip file containing a zip file...
+      unzip mame.zip
+      unzip -o ${messSrc}
+    '';
+
+  makeFlags = "TARGET=mess BUILD_EXPAT= BUILD_ZLIB= NOWERROR=1";
+
+  buildInputs =
+    [ unzip pkgconfig SDL gtk2 GConf libGLU_combined expat zlib ];
+
+  installPhase =
+    ''
+      mkdir -p $out/bin
+      cp mess* $out/bin/mess 
+    '';
+
+  meta = {
+    homepage = http://www.mess.org/;
+    license = "non-commercial";
+    description = "Multi Emulator Super System, an emulator of many game consoles and computer systems";
+    broken = true;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/mgba/default.nix b/nixpkgs/pkgs/misc/emulators/mgba/default.nix
new file mode 100644
index 000000000000..7fb804d31e41
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/mgba/default.nix
@@ -0,0 +1,70 @@
+{ stdenv, fetchFromGitHub, fetchpatch, makeDesktopItem, makeWrapper, pkgconfig
+, cmake, epoxy, libzip, ffmpeg, imagemagick, SDL2, qtbase, qtmultimedia, libedit
+, qttools, minizip }:
+
+let
+  desktopItem = makeDesktopItem {
+    name = "mgba";
+    exec = "mgba-qt";
+    icon = "mgba";
+    comment = "A Game Boy Advance Emulator";
+    desktopName = "mgba";
+    genericName = "Game Boy Advance Emulator";
+    categories = "Game;Emulator;";
+    startupNotify = "false";
+  };
+in stdenv.mkDerivation rec {
+  name = "mgba-${version}";
+  version = "0.6.3";
+
+  src = fetchFromGitHub {
+    owner = "mgba-emu";
+    repo = "mgba";
+    rev = version;
+    sha256 = "0m1pkxa6i94gq95cankv390wsbp88b3x41c7hf415rp9rkfq25vk";
+  };
+
+  enableParallelBuilding = true;
+  nativeBuildInputs = [ makeWrapper pkgconfig cmake ];
+
+  buildInputs = [
+    libzip epoxy ffmpeg imagemagick SDL2 qtbase qtmultimedia libedit minizip
+    qttools
+  ];
+
+  patches = [(fetchpatch {
+      url = "https://github.com/mgba-emu/mgba/commit/7f41dd354176b720c8e3310553c6b772278b9dca.patch";
+      sha256 = "0j334v8wf594kg8s1hngmh58wv1pi003z8avy6fjhj5qpjmbbavh";
+  })];
+
+  postInstall = ''
+    cp -r ${desktopItem}/share/applications $out/share
+    wrapProgram $out/bin/mgba-qt --suffix QT_PLUGIN_PATH : \
+      ${qtbase.bin}/${qtbase.qtPluginPrefix}
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://mgba.io;
+    description = "A modern GBA emulator with a focus on accuracy";
+
+    longDescription = ''
+      mGBA is a new Game Boy Advance emulator written in C.
+
+      The project started in April 2013 with the goal of being fast
+      enough to run on lower end hardware than other emulators
+      support, without sacrificing accuracy or portability. Even in
+      the initial version, games generally play without problems. It
+      is loosely based on the previous GBA.js emulator, although very
+      little of GBA.js can still be seen in mGBA.
+
+      Other goals include accurate enough emulation to provide a
+      development environment for homebrew software, a good workflow
+      for tool-assist runners, and a modern feature set for emulators
+      that older emulators may not support.
+    '';
+
+    license = licenses.mpl20;
+    maintainers = with maintainers; [ MP2E AndersonTorres ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/mupen64plus/default.nix b/nixpkgs/pkgs/misc/emulators/mupen64plus/default.nix
new file mode 100644
index 000000000000..9ff99110eccf
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/mupen64plus/default.nix
@@ -0,0 +1,29 @@
+{stdenv, fetchurl, boost, dash, freetype, libpng, pkgconfig, SDL, which, zlib }:
+
+stdenv.mkDerivation rec {
+  name = "mupen64plus-${version}";
+  version = "2.5";
+
+  src = fetchurl {
+    url = "https://github.com/mupen64plus/mupen64plus-core/releases/download/${version}/mupen64plus-bundle-src-${version}.tar.gz";
+    sha256 = "0rmsvfn4zfvbhz6gf1xkb7hnwflv6sbklwjz2xk4dlpj4vcbjxcw";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ boost dash freetype libpng SDL which zlib ];
+
+  buildPhase = ''
+    dash m64p_build.sh PREFIX="$out" COREDIR="$out/lib/" PLUGINDIR="$out/lib/mupen64plus" SHAREDIR="$out/share/mupen64plus"
+  '';
+  installPhase = ''
+    dash m64p_install.sh DESTDIR="$out" PREFIX=""
+  '';
+
+  meta = {
+    description = "A Nintendo 64 Emulator";
+    license = stdenv.lib.licenses.gpl2Plus;
+    homepage = http://www.mupen64plus.org/;
+    maintainers = [ stdenv.lib.maintainers.sander ];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/nestopia/build-fix.patch b/nixpkgs/pkgs/misc/emulators/nestopia/build-fix.patch
new file mode 100644
index 000000000000..a7d82ead15ca
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/nestopia/build-fix.patch
@@ -0,0 +1,18 @@
+diff -wbBur rdanbrook-nestopia-f1dde9b/Makefile rdanbrook-nestopia-f1dde9b.my/Makefile
+--- rdanbrook-nestopia-f1dde9b/Makefile	2013-01-20 20:10:25.000000000 +0400
++++ rdanbrook-nestopia-f1dde9b.my/Makefile	2013-01-21 15:18:54.727577673 +0400
+@@ -197,11 +197,11 @@
+ 	install -m 0644 NstDatabase.xml $(DATADIR)
+ 	install -m 0644 source/unix/icons/*.png $(DATADIR)/icons
+ 	install -m 0644 source/unix/icons/*.svg $(DATADIR)/icons
+-	install -m 0644 source/unix/icons/nestopia.svg $(PREFIX)/share/pixmaps
+-	xdg-desktop-menu install --novendor $(DATADIR)/nestopia.desktop
++	install -m 0644 source/unix/icons/nestopia.svg $(PREFIX)/share/pixmaps/nestopia.svg
++	install -Dm0644 $(DATADIR)/nestopia.desktop $(PREFIX)/share/applications/nestopia.desktop
+ 
+ uninstall:
+-	xdg-desktop-menu uninstall $(DATADIR)/nestopia.desktop
++	rm $(PREFIX)/share/applications/nestopia.desktop
+ 	rm $(PREFIX)/share/pixmaps/nestopia.svg
+ 	rm $(BINDIR)/$(BIN)
+ 	rm -rf $(DATADIR)
diff --git a/nixpkgs/pkgs/misc/emulators/nestopia/default.nix b/nixpkgs/pkgs/misc/emulators/nestopia/default.nix
new file mode 100644
index 000000000000..9eb353ede583
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/nestopia/default.nix
@@ -0,0 +1,72 @@
+{ stdenv, fetchFromGitHub, pkgconfig, SDL2, alsaLib, gtk3
+, makeWrapper, libGLU_combined, libarchive, libao, unzip, xdg_utils
+, epoxy, gdk_pixbuf, gnome3, wrapGAppsHook
+}:
+
+stdenv.mkDerivation rec {
+  version = "1.47";
+  name = "nestopia-${version}";
+
+  src = fetchFromGitHub {
+    owner = "rdanbrook";
+    repo = "nestopia";
+    rev = "${version}";
+    sha256 = "0frr0gvjh5mxzdhj0ii3sh671slgnzlm8naqlc4h87rx4p4sz2y2";
+  };
+
+  # nondeterministic failures when creating directories
+  enableParallelBuilding = false;
+
+  hardeningDisable = [ "format" ];
+
+  buildInputs = [
+    SDL2
+    alsaLib
+    epoxy
+    gtk3
+    gdk_pixbuf
+    libGLU_combined
+    libarchive
+    libao
+    unzip
+    xdg_utils
+    gnome3.adwaita-icon-theme
+  ];
+
+  nativeBuildInputs = [
+    pkgconfig
+    makeWrapper
+    wrapGAppsHook
+  ];
+
+  installPhase = ''
+    mkdir -p $out/{bin,share/nestopia}
+    make install PREFIX=$out
+  '';
+
+  preFixup = ''
+     for f in $out/bin/*; do
+       wrapProgram $f \
+         --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH:$out/share"
+     done
+  '';
+
+  patches = [
+    #(fetchpatch {
+    #  url = "https://github.com/rdanbrook/nestopia/commit/f4bc74ac4954328b25e961e7afb7337377084079.patch";
+    #  name = "gcc6.patch";
+    #  sha256 = "1jy0c85xsfk9hrv5a6v0kk48d94864qb62yyni9fp93kyl33y2p4";
+    #})
+    ./gcc6.patch
+    ./build-fix.patch
+  ];
+
+  meta = {
+    homepage = http://0ldsk00l.ca/nestopia/;
+    description = "NES emulator with a focus on accuracy";
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+    maintainers = with stdenv.lib.maintainers; [ MP2E ];
+  };
+}
+
diff --git a/nixpkgs/pkgs/misc/emulators/nestopia/gcc6.patch b/nixpkgs/pkgs/misc/emulators/nestopia/gcc6.patch
new file mode 100644
index 000000000000..65dcc72c0c25
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/nestopia/gcc6.patch
@@ -0,0 +1,92 @@
+From f4bc74ac4954328b25e961e7afb7337377084079 Mon Sep 17 00:00:00 2001
+From: David Seifert <soap@gentoo.org>
+Date: Sat, 31 Dec 2016 18:21:18 +0200
+Subject: [PATCH] Fix compiling in C++14 mode
+
+* Left shifting a negative signed is undefined behaviour
+* Fix incorrect printf() specifiers found with -Wformat
+---
+ source/core/NstCore.hpp            | 4 ++--
+ source/unix/gtkui/gtkui.cpp        | 2 +-
+ source/unix/gtkui/gtkui.h          | 1 -
+ source/unix/gtkui/gtkui_cheats.cpp | 8 ++++----
+ source/unix/video.cpp              | 2 +-
+ 5 files changed, 8 insertions(+), 9 deletions(-)
+
+diff --git a/source/core/NstCore.hpp b/source/core/NstCore.hpp
+index 50e20f6..420cc4a 100644
+--- a/source/core/NstCore.hpp
++++ b/source/core/NstCore.hpp
+@@ -279,14 +279,14 @@ namespace Nes
+ 		template<typename T>

+ 		inline long signed_shl(T v,uint c)

+ 		{

+-			enum {NATIVE = T(-7) << 1 == -14};

++			enum {NATIVE = -(T(7) << 1) == -14};

+ 			return Helper::ShiftSigned<T,NATIVE>::Left( v, c );

+ 		}

+ 

+ 		template<typename T>

+ 		inline long signed_shr(T v,uint c)

+ 		{

+-			enum {NATIVE = T(-7) >> 1 == -4 || T(-7) >> 1 == -3};

++			enum {NATIVE = -(T(7) >> 1) == -4 || -(T(7) >> 1) == -3};

+ 			return Helper::ShiftSigned<T,NATIVE>::Right( v, c );

+ 		}

+ 

+diff --git a/source/unix/gtkui/gtkui.cpp b/source/unix/gtkui/gtkui.cpp
+index 3cfeeab..d4a5e2d 100644
+--- a/source/unix/gtkui/gtkui.cpp
++++ b/source/unix/gtkui/gtkui.cpp
+@@ -438,7 +438,7 @@ void gtkui_message(const char* message) {
+ 				GTK_DIALOG_DESTROY_WITH_PARENT,
+ 				GTK_MESSAGE_INFO,
+ 				GTK_BUTTONS_OK,
+-				message);
++				"%s", message);
+ 	gtk_dialog_run(GTK_DIALOG(messagewindow));
+ 	gtk_widget_destroy(messagewindow);
+ }
+diff --git a/source/unix/gtkui/gtkui_cheats.cpp b/source/unix/gtkui/gtkui_cheats.cpp
+index afc01b0..e7b691a 100644
+--- a/source/unix/gtkui/gtkui_cheats.cpp
++++ b/source/unix/gtkui/gtkui_cheats.cpp
+@@ -373,7 +373,7 @@ void gtkui_cheats_fill_tree(char *filename) {
+ 				else if (node.GetChild(L"address")) { // Raw
+ 					char rawbuf[11];
+ 					snprintf(rawbuf, sizeof(rawbuf),
+-								"%04x %02x %02x",
++								"%04lu %02lu %02lu",
+ 								node.GetChild(L"address").GetUnsignedValue(),
+ 								node.GetChild(L"value").GetUnsignedValue(),
+ 								node.GetChild(L"compare").GetUnsignedValue());
+@@ -545,13 +545,13 @@ gboolean gtkui_cheats_scan_list(GtkTreeModel *model, GtkTreePath *path, GtkTreeI
+ 			int addr, value, compare;
+ 			char buf[5];
+ 			
+-			snprintf(buf, sizeof(buf), "%c%c%c%c\0", rawcode[0], rawcode[1], rawcode[2], rawcode[3]);
++			snprintf(buf, sizeof(buf), "%c%c%c%c", rawcode[0], rawcode[1], rawcode[2], rawcode[3]);
+ 			sscanf(buf, "%x", &addr);
+ 			
+-			snprintf(buf, sizeof(buf), "%c%c\0", rawcode[5], rawcode[6]);
++			snprintf(buf, sizeof(buf), "%c%c", rawcode[5], rawcode[6]);
+ 			sscanf(buf, "%x", &value);
+ 			
+-			snprintf(buf, sizeof(buf), "%c%c\0", rawcode[8], rawcode[9]);
++			snprintf(buf, sizeof(buf), "%c%c", rawcode[8], rawcode[9]);
+ 			sscanf(buf, "%x", &compare);
+ 			
+ 			code.address = addr;
+diff --git a/source/unix/video.cpp b/source/unix/video.cpp
+index 3eff19d..c34bb22 100644
+--- a/source/unix/video.cpp
++++ b/source/unix/video.cpp
+@@ -757,7 +757,7 @@ void video_screenshot(const char* filename) {
+ 	if (filename == NULL) {
+ 		// Set the filename
+ 		char sshotpath[512];
+-		snprintf(sshotpath, sizeof(sshotpath), "%sscreenshots/%s-%d-%d.png", nstpaths.nstdir, nstpaths.gamename, time(NULL), rand() % 899 + 100);
++		snprintf(sshotpath, sizeof(sshotpath), "%sscreenshots/%s-%ld-%d.png", nstpaths.nstdir, nstpaths.gamename, time(NULL), rand() % 899 + 100);
+ 		
+ 		// Save the file
+ 		lodepng_encode32_file(sshotpath, (const unsigned char*)pixels, rendersize.w, rendersize.h);
diff --git a/nixpkgs/pkgs/misc/emulators/openmsx/custom-nixos.mk b/nixpkgs/pkgs/misc/emulators/openmsx/custom-nixos.mk
new file mode 100644
index 000000000000..9098762e40d5
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/openmsx/custom-nixos.mk
@@ -0,0 +1,9 @@
+# This file substitutes $sourceRoot/build/custom.mk
+
+VERSION_EXEC:=false
+SYMLINK_FOR_BINARY:=false
+INSTALL_CONTRIB:=true
+INSTALL_BASE:=${out}
+INSTALL_DOC_DIR:=${INSTALL_BASE}/share/doc/openmsx
+INSTALL_SHARE_DIR:=${INSTALL_BASE}/share/openmsx
+INSTALL_BINARY_DIR:=${INSTALL_BASE}/bin
diff --git a/nixpkgs/pkgs/misc/emulators/openmsx/default.nix b/nixpkgs/pkgs/misc/emulators/openmsx/default.nix
new file mode 100644
index 000000000000..d2539cbc8171
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/openmsx/default.nix
@@ -0,0 +1,48 @@
+{ stdenv, fetchFromGitHub, pkgconfig
+, python
+, alsaLib, glew, libGL, libpng
+, libogg, libtheora, libvorbis
+, SDL, SDL_image, SDL_ttf
+, freetype, tcl, zlib
+}:
+
+stdenv.mkDerivation rec {
+
+  name = "openmsx-${version}";
+  version = "git-2017-11-02";
+
+  src = fetchFromGitHub {
+    owner = "openMSX";
+    repo = "openMSX";
+    rev = "eeb74206ae347a3b17e9b99f91f2b4682c5db22c";
+    sha256 = "170amj7k6wjhwx6psbplqljvckvhxxbv3aw72jrdxl1fb8zlnq3s";
+    fetchSubmodules = true;
+  };
+
+  nativeBuildInputs = [ pkgconfig python ];
+
+  buildInputs = [ alsaLib glew libGL libpng
+    libogg libtheora libvorbis freetype
+    SDL SDL_image SDL_ttf tcl zlib ];
+
+  postPatch = ''
+    cp ${./custom-nixos.mk} build/custom.mk
+  '';
+
+  dontAddPrefix = true;
+
+  # Many thanks @mthuurne from OpenMSX project
+  # for providing support to Nixpkgs :)
+  TCL_CONFIG="${tcl}/lib/";
+
+  meta = with stdenv.lib; {
+    description = "A MSX emulator";
+    longDescription = ''
+      OpenMSX is an emulator for the MSX home computer system. Its goal is
+      to emulate all aspects of the MSX with 100% accuracy.
+    '';
+    homepage = https://openmsx.org;
+    maintainers = with maintainers; [ AndersonTorres ];
+    platforms = platforms.unix;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/pcsx2/default.nix b/nixpkgs/pkgs/misc/emulators/pcsx2/default.nix
new file mode 100644
index 000000000000..95e94eeaff51
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/pcsx2/default.nix
@@ -0,0 +1,74 @@
+{ alsaLib, cmake, fetchFromGitHub, glib, gtk2, gettext, libaio, libpng
+, makeWrapper, perl, pkgconfig, portaudio, SDL2, soundtouch, stdenv
+, wxGTK30, zlib }:
+
+stdenv.mkDerivation rec {
+  name = "pcsx2-${version}";
+  version = "1.4.0";
+
+  src = fetchFromGitHub {
+    owner = "PCSX2";
+    repo = "pcsx2";
+    rev = "v${version}";
+    sha256 = "0s7mxq2cgzwjfsq0vhpz6ljk7wr725nxg48128iyirf85585l691";
+  };
+
+  postPatch = "sed '1i#include \"x86intrin.h\"' -i common/src/x86emitter/cpudetect.cpp";
+
+  configurePhase = ''
+    mkdir -p build
+    cd build
+
+    cmake \
+      -DBIN_DIR="$out/bin" \
+      -DCMAKE_BUILD_PO=TRUE \
+      -DCMAKE_BUILD_TYPE=Release \
+      -DCMAKE_INSTALL_PREFIX="$out" \
+      -DDISABLE_ADVANCE_SIMD=TRUE \
+      -DDISABLE_PCSX2_WRAPPER=TRUE \
+      -DDOC_DIR="$out/share/doc/pcsx2" \
+      -DGAMEINDEX_DIR="$out/share/pcsx2" \
+      -DGLSL_SHADER_DIR="$out/share/pcsx2" \
+      -DGTK2_GLIBCONFIG_INCLUDE_DIR='${glib.out}/lib/glib-2.0/include' \
+      -DGTK2_GDKCONFIG_INCLUDE_DIR='${gtk2.out}/lib/gtk-2.0/include' \
+      -DGTK2_INCLUDE_DIRS='${gtk2.dev}/include/gtk-2.0' \
+      -DPACKAGE_MODE=TRUE \
+      -DPLUGIN_DIR="$out/lib/pcsx2" \
+      -DREBUILD_SHADER=TRUE \
+      ..
+  '';
+
+  postFixup = ''
+    wrapProgram $out/bin/PCSX2 \
+      --set __GL_THREADED_OPTIMIZATIONS 1
+  '';
+
+  nativeBuildInputs = [ cmake perl pkgconfig ];
+
+  buildInputs = [
+    alsaLib glib gettext gtk2 libaio libpng makeWrapper portaudio SDL2
+    soundtouch wxGTK30 zlib
+  ];
+
+  enableParallelBuilding = true;
+
+  meta = with stdenv.lib; {
+    description = "Playstation 2 emulator";
+    longDescription= ''
+      PCSX2 is an open-source PlayStation 2 (AKA PS2) emulator. Its purpose
+      is to emulate the PS2 hardware, using a combination of MIPS CPU
+      Interpreters, Recompilers and a Virtual Machine which manages hardware
+      states and PS2 system memory. This allows you to play PS2 games on your
+      PC, with many additional features and benefits.
+    '';
+    homepage = https://pcsx2.net;
+    maintainers = with maintainers; [ hrdinka ];
+
+    # PCSX2's source code is released under LGPLv3+. It However ships
+    # additional data files and code that are licensed differently.
+    # This might be solved in future, for now we should stick with
+    # license.free
+    license = licenses.free;
+    platforms = platforms.i686;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/pcsxr/default.nix b/nixpkgs/pkgs/misc/emulators/pcsxr/default.nix
new file mode 100644
index 000000000000..5af3042bde4d
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/pcsxr/default.nix
@@ -0,0 +1,87 @@
+{ stdenv, fetchurl, autoreconfHook, intltool, pkgconfig, gtk3, SDL2, xorg
+, wrapGAppsHook, libcdio, nasm, ffmpeg, file
+, fetchpatch }:
+
+stdenv.mkDerivation rec {
+  name = "pcsxr-${version}";
+  version = "1.9.94";
+
+  # codeplex does not support direct downloading
+  src = fetchurl {
+    url = "mirror://debian/pool/main/p/pcsxr/pcsxr_${version}.orig.tar.xz";
+    sha256 = "0q7nj0z687lmss7sgr93ij6my4dmhkm2nhjvlwx48dn2lxl6ndla";
+  };
+
+  patches = [
+    ( fetchpatch {
+      url = "https://anonscm.debian.org/cgit/pkg-games/pcsxr.git/plain/debian/patches/01_fix-i386-exec-stack.patch?h=debian/1.9.94-2";
+      sha256 = "17497wjxd6b92bj458s2769d9bpp68ydbvmfs9gp51yhnq4zl81x";
+    })
+    ( fetchpatch {
+      url = "https://anonscm.debian.org/cgit/pkg-games/pcsxr.git/plain/debian/patches/02_disable-ppc-auto-dynarec.patch?h=debian/1.9.94-2";
+      sha256 = "0v8n79z034w6cqdrzhgd9fkdpri42mzvkdjm19x4asz94gg2i2kf";
+    })
+    ( fetchpatch {
+      url = "https://anonscm.debian.org/cgit/pkg-games/pcsxr.git/plain/debian/patches/03_fix-plugin-dir.patch?h=debian/1.9.94-2";
+      sha256 = "0vkl0mv6whqaz79kvvvlmlmjpynyq4lh352j3bbxcr0vjqffxvsy";
+    })
+    ( fetchpatch {
+      url = "https://anonscm.debian.org/cgit/pkg-games/pcsxr.git/plain/debian/patches/04_update-homedir-symlinks.patch?h=debian/1.9.94-2";
+      sha256 = "18r6n025ybr8fljfsaqm4ap31wp8838j73lrsffi49fkis60dp4j";
+    })
+    ( fetchpatch {
+      url = "https://anonscm.debian.org/cgit/pkg-games/pcsxr.git/plain/debian/patches/05_format-security.patch?h=debian/1.9.94-2";
+      sha256 = "03m4kfc9bk5669hf7ji1anild08diliapx634f9cigyxh72jcvni";
+    })
+    ( fetchpatch {
+      url = "https://anonscm.debian.org/cgit/pkg-games/pcsxr.git/plain/debian/patches/06_warnings.patch?h=debian/1.9.94-2";
+      sha256 = "0iz3g9ihnhisfgrzma9l74y4lhh57na9h41bmiam1millb796g71";
+    })
+    ( fetchpatch {
+      url = "https://anonscm.debian.org/cgit/pkg-games/pcsxr.git/plain/debian/patches/07_non-linux-ip-addr.patch?h=debian/1.9.94-2";
+      sha256 = "14vb9l0l4nzxcymhjjs4q57nmsncmby9qpdr7c19rly5wavm4k77";
+    })
+    ( fetchpatch {
+      url = "https://anonscm.debian.org/cgit/pkg-games/pcsxr.git/plain/debian/patches/08_reproducible.patch?h=debian/1.9.94-2";
+      sha256 = "1cx9q59drsk9h6l31097lg4aanaj93ysdz5p88pg9c7wvxk1qz06";
+    })
+
+    ./uncompress2.patch
+  ];
+
+  nativeBuildInputs = [ autoreconfHook intltool pkgconfig wrapGAppsHook ];
+  buildInputs = [
+    gtk3 SDL2 xorg.libXv xorg.libXtst libcdio nasm ffmpeg file
+  ];
+
+  dynarecTarget =
+   if stdenv.isx86_64 then "x86_64"
+   else if stdenv.isi686 then "x86"
+   else "no"; #debian patch 2 says ppc doesn't work
+
+  configureFlags = [
+    "--enable-opengl"
+    "--enable-ccdda"
+    "--enable-libcdio"
+    "--enable-dynarec=${dynarecTarget}"
+  ];
+
+  postInstall = ''
+    mkdir -p "$out/share/doc/${name}"
+    cp README \
+       AUTHORS \
+       doc/keys.txt \
+       doc/tweaks.txt \
+       ChangeLog.df \
+       ChangeLog \
+       "$out/share/doc/${name}"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Playstation 1 emulator";
+    homepage = https://pcsxr.codeplex.com/;
+    maintainers = with maintainers; [ rardiol ];
+    license = licenses.gpl2Plus;
+    platforms = platforms.all;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/pcsxr/uncompress2.patch b/nixpkgs/pkgs/misc/emulators/pcsxr/uncompress2.patch
new file mode 100644
index 000000000000..356868ce7a8b
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/pcsxr/uncompress2.patch
@@ -0,0 +1,20 @@
+--- a/libpcsxcore/cdriso.c
++++ b/libpcsxcore/cdriso.c
+@@ -1219,7 +1219,7 @@
+ 	return ret;
+ }
+ 
+-static int uncompress2(void *out, unsigned long *out_size, void *in, unsigned long in_size)
++static int uncompress3(void *out, unsigned long *out_size, void *in, unsigned long in_size)
+ {
+ 	static z_stream z;
+ 	int ret = 0;
+@@ -1298,7 +1298,7 @@
+ 	if (is_compressed) {
+ 		cdbuffer_size_expect = sizeof(compr_img->buff_raw[0]) << compr_img->block_shift;
+ 		cdbuffer_size = cdbuffer_size_expect;
+-		ret = uncompress2(compr_img->buff_raw[0], &cdbuffer_size, compr_img->buff_compressed, size);
++		ret = uncompress3(compr_img->buff_raw[0], &cdbuffer_size, compr_img->buff_compressed, size);
+ 		if (ret != 0) {
+ 			SysPrintf("uncompress failed with %d for block %d, sector %d\n",
+ 					ret, block, sector);
diff --git a/nixpkgs/pkgs/misc/emulators/ppsspp/default.nix b/nixpkgs/pkgs/misc/emulators/ppsspp/default.nix
new file mode 100644
index 000000000000..159eefad6662
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/ppsspp/default.nix
@@ -0,0 +1,45 @@
+{ stdenv, fetchFromGitHub, cmake, pkgconfig, qtbase, qtmultimedia
+, glew, libzip, snappy, zlib, withGamepads ? true, SDL2 }:
+
+assert withGamepads -> (SDL2 != null);
+with stdenv.lib;
+
+stdenv.mkDerivation rec {
+  name = "ppsspp-${version}";
+  version = "1.4.2";
+
+  src = fetchFromGitHub {
+    owner = "hrydgard";
+    repo = "ppsspp";
+    rev = "v${version}";
+    fetchSubmodules = true;
+    sha256 = "0m4qkhx7q496sm7ibg2n7rm3npxzfr93iraxgndk0vhfk8vy8w75";
+  };
+
+  patchPhase = ''
+    echo 'const char *PPSSPP_GIT_VERSION = "${src.rev}";' >> git-version.cpp
+    substituteInPlace UI/NativeApp.cpp --replace /usr/share $out/share
+  '';
+
+  nativeBuildInputs = [ cmake pkgconfig ];
+  buildInputs = [ qtbase qtmultimedia glew libzip snappy zlib ]
+    ++ optionals withGamepads [ SDL2 SDL2.dev ];
+
+  cmakeFlags = [ "-DCMAKE_BUILD_TYPE=Release" "-DUSING_QT_UI=ON" ];
+
+  installPhase = ''
+    mkdir -p $out/bin $out/share/ppsspp
+    mv PPSSPPQt $out/bin/ppsspp
+    mv assets $out/share/ppsspp
+  '';
+
+  enableParallelBuilding = true;
+
+  meta = {
+    homepage = https://www.ppsspp.org/;
+    description = "A PSP emulator for Android, Windows, Mac and Linux, written in C++";
+    license = licenses.gpl2Plus;
+    maintainers = with maintainers; [ fuuzetsu AndersonTorres ];
+    platforms = platforms.linux ++ platforms.darwin ++ platforms.cygwin;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/qmc2/default.nix b/nixpkgs/pkgs/misc/emulators/qmc2/default.nix
new file mode 100644
index 000000000000..65cc0bd9c05a
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/qmc2/default.nix
@@ -0,0 +1,40 @@
+{ stdenv
+, fetchurl, qttools, pkgconfig
+, minizip, zlib
+, qtbase, qtsvg, qtmultimedia, qtwebkit, qttranslations, qtxmlpatterns
+, rsync, SDL2, xwininfo
+, utillinux
+, xorg
+}:
+
+stdenv.mkDerivation rec {
+  name = "qmc2-${version}";
+  version = "0.195";
+
+  src = fetchurl {
+      url = "mirror://sourceforge/project/qmc2/qmc2/${version}/${name}.tar.gz";
+      sha256 = "1dzmjlfk8pdspns6zg1jmd5fqzg8igd4q38cz4a1vf39lx74svns";
+  };
+  
+  preBuild = ''
+    patchShebangs scripts
+  '';
+
+  nativeBuildInputs = [ qttools pkgconfig ];
+  buildInputs = [ minizip qtbase qtsvg qtmultimedia qtwebkit
+                  qttranslations qtxmlpatterns rsync SDL2
+                  xwininfo zlib utillinux xorg.libxcb ];
+
+  makeFlags = [ "DESTDIR=$(out)"
+                "PREFIX=/"
+                "DATADIR=/share/"
+                "SYSCONFDIR=/etc" ];
+
+  meta = with stdenv.lib; {
+    description = "A Qt frontend for MAME/MESS";
+    homepage = https://qmc2.batcom-it.net;
+    license = licenses.gpl2;
+    maintainers = [ maintainers.genesis ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/retroarch/cores.nix b/nixpkgs/pkgs/misc/emulators/retroarch/cores.nix
new file mode 100644
index 000000000000..3f20390fba73
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/retroarch/cores.nix
@@ -0,0 +1,456 @@
+{ stdenv, fetchgit, fetchFromGitLab, cmake, pkgconfig, makeWrapper, python27, retroarch
+, alsaLib, fluidsynth, curl, hidapi, libGLU_combined, gettext, glib, gtk2, portaudio, SDL
+, ffmpeg, pcre, libevdev, libpng, libjpeg, udev, libvorbis
+, miniupnpc, sfml, xorg, zlib }:
+
+let
+
+  d2u = stdenv.lib.replaceChars ["-"] ["_"];
+
+  mkLibRetroCore = ({ core, src, description, license, ... }@a:
+  stdenv.lib.makeOverridable stdenv.mkDerivation rec {
+
+    name = "libretro-${core}-${version}";
+    version = "2017-06-04";
+    inherit src;
+
+    buildInputs = [ makeWrapper retroarch zlib ] ++ a.extraBuildInputs or [];
+
+    makefile = "Makefile.libretro";
+
+    installPhase = ''
+      COREDIR="$out/lib/retroarch/cores"
+      mkdir -p $out/bin
+      mkdir -p $COREDIR
+      mv ${d2u core}_libretro${stdenv.hostPlatform.extensions.sharedLibrary} $COREDIR/.
+      makeWrapper ${retroarch}/bin/retroarch $out/bin/retroarch-${core} \
+        --add-flags "-L $COREDIR/${d2u core}_libretro${stdenv.hostPlatform.extensions.sharedLibrary} $@"
+    '';
+
+    enableParallelBuilding = true;
+
+    passthru = {
+      core = core;
+      libretroCore = "/lib/retroarch/cores";
+    };
+
+    meta = with stdenv.lib; {
+      inherit description;
+      homepage = https://www.libretro.com/;
+      inherit license;
+      maintainers = with maintainers; [ edwtjo hrdinka MP2E ];
+      platforms = platforms.unix;
+    };
+  } // a);
+
+  fetchRetro = { repo, rev, sha256 }:
+  fetchgit {
+    inherit rev sha256;
+    url = "https://github.com/libretro/${repo}.git";
+    fetchSubmodules = true;
+  };
+
+in with stdenv.lib.licenses;
+
+{
+
+  _4do = (mkLibRetroCore rec {
+    core = "4do";
+    src = fetchRetro {
+      repo = core + "-libretro";
+      rev = "52d881743dd8614d96b4de8bd153cb725b87d474";
+      sha256 = "1n42f70vni2zavppayaq8xmsyx5cn40qi4zk4pgq1w3hh2q8mj72";
+    };
+    description = "Port of 4DO/libfreedo to libretro";
+    license = "Non-commercial";
+  }).override {
+    buildPhase = "make";
+  };
+
+  beetle-pce-fast = let der = (mkLibRetroCore rec {
+    core = "mednafen-pce-fast";
+    src = fetchRetro {
+      repo = "beetle-pce-fast-libretro";
+      rev = "2954e645d668ee73d93803dc30da4462fc7a459b";
+      sha256 = "0p0k7kqfd6xg1qh6vgzgwp122miprb2bpzljgxd9kvigxihsl6f7";
+    };
+    description = "Port of Mednafen's PC Engine core to libretro";
+    license = gpl2;
+  }); in der.override {
+    buildPhase = "make";
+    name = "beetle-pce-fast-${der.version}";
+  };
+
+  beetle-psx = let der = (mkLibRetroCore rec {
+    core = "mednafen-psx";
+    src = fetchRetro {
+      repo = "beetle-psx-libretro";
+      rev = "76862abefdde9097561e2b795e75b49247deff17";
+      sha256 = "1k4b7g50ajzchjrm6d3v68hvri4k3hzvacn2l99i5yq3hxp7vs7x";
+    };
+    description = "Port of Mednafen's PSX Engine core to libretro";
+    license = gpl2;
+  }); in der.override {
+    buildPhase = "make";
+    name = "beetle-psx-${der.version}";
+  };
+
+  beetle-saturn = let der = (mkLibRetroCore rec {
+    core = "mednafen-saturn";
+    src = fetchRetro {
+      repo = "beetle-saturn-libretro";
+      rev = "3f1661b39ef249e105e6e2e655854ad0c87cd497";
+      sha256 = "1d1brysynwr6inlwfgv7gwkl3i9mf4lsaxd9wm2szw86g4diyn4c";
+    };
+    description = "Port of Mednafen's Saturn core to libretro";
+    license = gpl2;
+  }); in der.override {
+    buildPhase = "make";
+    name = "beetle-saturn-${der.version}";
+    meta.platforms = [ "x86_64-linux" ];
+  };
+
+  bsnes-mercury = let bname = "bsnes-mercury"; in (mkLibRetroCore rec {
+    core = bname + "-accuracy";
+    src = fetchRetro {
+      repo = bname;
+      rev = "e89c9a2e0a12d588366ee4f5c76b7d75139d938b";
+      sha256 = "0vkn1f38vwazpp3kbvvv8c467ghak6yfx00s48wkxwvhmak74a3s";
+    };
+    description = "Fork of bsnes with HLE DSP emulation restored";
+    license = gpl3;
+  }).override {
+    buildPhase = "make && cd out";
+  };
+
+  desmume = (mkLibRetroCore rec {
+    core = "desmume";
+    src = fetchRetro {
+      repo = core;
+      rev = "ce1f93abb4c3aa55099f56298e5438a03a3c2bbd";
+      sha256 = "064gzfbr7yizmvi91ry5y6bzikj633kdqhvzycb9f1g6kspf8yyl";
+    };
+    description = "libretro wrapper for desmume NDS emulator";
+    license = gpl2;
+  }).override {
+    configurePhase = "cd desmume";
+  };
+
+  dolphin = (mkLibRetroCore {
+    core = "dolphin";
+    src = fetchRetro {
+      repo = "dolphin";
+      rev = "a6ad451fdd4ac8753fd1a8e2234ec34674677754";
+      sha256 = "1cshlfmhph8dl3vgvn37imvp2b7xs2cx1r1ifp5js5psvhycrbz3";
+    };
+    description = "Port of Dolphin to libretro";
+    license = gpl2Plus;
+
+    extraBuildInputs = [
+      cmake curl libGLU_combined pcre pkgconfig sfml miniupnpc
+      gettext glib gtk2 hidapi
+      libevdev udev
+    ] ++ (with xorg; [ libSM libX11 libXi libpthreadstubs libxcb xcbutil libXinerama libXxf86vm ]);
+  }).override {
+    cmakeFlags = [
+        "-DLINUX_LOCAL_DEV=true"
+        "-DGTK2_GDKCONFIG_INCLUDE_DIR=${gtk2.out}/lib/gtk-2.0/include"
+        "-DGTK2_GLIBCONFIG_INCLUDE_DIR=${glib.out}/lib/glib-2.0/include"
+        "-DGTK2_INCLUDE_DIRS=${gtk2.dev}/include/gtk-2.0"
+    ];
+    dontUseCmakeBuildDir = "yes";
+    buildPhase = ''
+      cd Source/Core/DolphinLibretro
+      make
+    '';
+  };
+
+  fba = (mkLibRetroCore rec {
+    core = "fba";
+    src = fetchRetro {
+      repo = core + "-libretro";
+      rev = "9146c18ac989c619256d1cb8954d49e728e44ea3";
+      sha256 = "159dww8mxi95xz4ypw38vsn1g4k6z8sv415qqf0qriydwhw6mh2m";
+    };
+    description = "Port of Final Burn Alpha to libretro";
+    license = "Non-commercial";
+  }).override {
+    buildPhase = ''
+      cd svn-current/trunk \
+      && make -f makefile.libretro \
+      && mv fbalpha2012_libretro${stdenv.hostPlatform.extensions.sharedLibrary} fba_libretro${stdenv.hostPlatform.extensions.sharedLibrary}
+    '';
+  };
+
+  fceumm = mkLibRetroCore rec {
+    core = "fceumm";
+    src = fetchRetro {
+      repo = "libretro-" + core;
+      rev = "45f773a1c221121746bbe2680e3aaaf92776a87e";
+      sha256 = "0jnwh1338q710x47bzrx319g5xbq9ipv35kyjlbkrzhqjq1blz0b";
+    };
+    description = "FCEUmm libretro port";
+    license = gpl2;
+  };
+
+  gambatte = mkLibRetroCore rec {
+    core = "gambatte";
+    src = fetchRetro {
+      repo = core + "-libretro";
+      rev = "db7af6cf6ea39fd5e39eea137ff752649599a4e4";
+      sha256 = "0h7hyj630nk1s32wx02y4q9x2lp6wbnh6nkc9ihf4pygcsignmwr";
+    };
+    description = "Gambatte libretro port";
+    license = gpl2;
+  };
+
+  genesis-plus-gx = mkLibRetroCore rec {
+    core = "genesis-plus-gx";
+    src = fetchRetro {
+      repo = "Genesis-Plus-GX";
+      rev = "365a28c7349b691e6aaa3ad59b055261c42bd130";
+      sha256 = "0s11ddpnb44q4xjkl7dylldhi9y5zqywqavpk0bbwyj84r1cbz3c";
+    };
+    description = "Enhanced Genesis Plus libretro port";
+    license = "Non-commercial";
+  };
+
+  higan-sfc = (mkLibRetroCore rec {
+    core = "higan-sfc";
+    src = fetchFromGitLab {
+      owner = "higan";
+      repo = "higan";
+      rev = "d3f592013a27cb78f17d84f90a6be6cf6f6af1d1";
+      sha256 = "19d4cbwg8d085xq5lmql4v5l4ckgwqzc59ha5yfgv3w4qfp4dmij";
+    };
+    description = "Accurate SNES / Super Famicom emulator";
+    license = gpl3;
+  }).override {
+    makefile = "GNUmakefile";
+    buildPhase = "cd higan && make compiler=g++ target=libretro binary=library && cd out";
+  };
+
+  mame = (mkLibRetroCore {
+    core = "mame";
+    src = fetchRetro {
+      repo = "mame";
+      rev = "9f9e6b6c9bde4d50c72e9a5c80496a1fec6b8aa9";
+      sha256 = "0lfj8bjchkcvyb5x0x29cg10fkfklxndk80947k4qfysclijxpkv";
+    };
+    description = "Port of MAME to libretro";
+    license = gpl2Plus;
+
+    extraBuildInputs = [ alsaLib libGLU_combined portaudio python27 xorg.libX11 ];
+  }).override {
+    postPatch = ''
+      # Prevent the failure during the parallel building of:
+      # make -C 3rdparty/genie/build/gmake.linux -f genie.make obj/Release/src/host/lua-5.3.0/src/lgc.o
+      mkdir -p 3rdparty/genie/build/gmake.linux/obj/Release/src/host/lua-5.3.0/src
+    '';
+  };
+
+  mgba = mkLibRetroCore rec {
+    core = "mgba";
+    src = fetchRetro {
+      repo = core;
+      rev = "fdaaaee661e59f28c94c7cfa4e82e70b71e24a9d";
+      sha256 = "1b30sa861r4bhbqkx6vkklh4iy625bpzki2ks4ivvjns1ijczvc7";
+    };
+    description = "Port of mGBA to libretro";
+    license = mpl20;
+  };
+
+  mupen64plus = (mkLibRetroCore rec {
+    core = "mupen64plus";
+    src = fetchRetro {
+      repo = core + "-libretro";
+      rev = "407bcd40b3a42bff6b856a6d6f88a7d5d670bf9e";
+      sha256 = "0q5kvjz7rpk7mp75cdywqjgmy10c0h7ky26hh1x90d39y94idcd8";
+    };
+    description = "Libretro port of Mupen64 Plus, GL only";
+    license = gpl2;
+
+    extraBuildInputs = [ libGLU_combined libpng ];
+  }).override {
+    buildPhase = "make WITH_DYNAREC=${if stdenv.hostPlatform.system == "x86_64-linux" then "x86_64" else "x86"}";
+  };
+
+  nestopia = (mkLibRetroCore rec {
+    core = "nestopia";
+    src = fetchRetro {
+      repo = core;
+      rev = "ecfa170a582e5b8ec11225ca645843fa064955ca";
+      sha256 = "17ac7dhasch6f4lpill8c5scsvaix0jvbf1cp797qbll4hk84f2q";
+    };
+    description = "nestopia undead libretro port";
+    license = gpl2;
+  }).override {
+    buildPhase = "cd libretro && make";
+  };
+
+  parallel-n64 = (mkLibRetroCore rec {
+    core = "parallel-n64";
+    src = fetchRetro {
+      repo = core;
+      rev = "3276db27547bf7ca85896427f0b82d4658694d88";
+      sha256 = "19396v50azrb52ifjk298zgcbxn8dvfvp6zwrnzsk6mp8ff7qcqw";
+    };
+    description = "Parallel Mupen64plus rewrite for libretro.";
+    license = gpl2;
+
+    extraBuildInputs = [ libGLU_combined libpng ];
+  }).override {
+    buildPhase = "make WITH_DYNAREC=${if stdenv.hostPlatform.system == "x86_64-linux" then "x86_64" else "x86"}";
+  };
+
+  picodrive = (mkLibRetroCore rec {
+    core = "picodrive";
+    src = fetchRetro {
+      repo = core;
+      rev = "cbc93b68dca1d72882d07b54bbe1ef25b980558a";
+      sha256 = "0fl9r6jj2x9231md5zc4scra79j5hfn1n2z67scff1375xg1k64h";
+    };
+    description = "Fast MegaDrive/MegaCD/32X emulator";
+    license = "MAME";
+
+    extraBuildInputs = [ libpng SDL ];
+  }).override {
+    patchPhase = "sed -i -e 's,SDL_CONFIG=\".*\",SDL_CONFIG=\"${SDL.dev}/bin/sdl-config\",' configure";
+    configurePhase = "./configure";
+  };
+
+  ppsspp = (mkLibRetroCore rec {
+    core = "ppsspp";
+    src = fetchRetro {
+      repo = "libretro-" + core;
+      rev = "5f7bcf7bfc15f83d405bcecd7a163a55ad1e7573";
+      sha256 = "06k1gzmypz61dslynrw4b5i161rhj43y6wnr2nhbzvwcv5bw8w8r";
+    };
+    description = "ppsspp libretro port";
+    license = gpl2;
+    extraBuildInputs = [ libGLU_combined ffmpeg ];
+  }).override {
+    buildPhase = "cd libretro && make";
+  };
+
+  prboom = (mkLibRetroCore rec {
+    core = "prboom";
+    src = fetchRetro {
+      repo = "libretro-" + core;
+      rev = "4c690eb6b569a276c5b2a87680718f715477eae2";
+      sha256 = "02vkl3y5dmyzifsviphspqv03a2rdyf36zpjpgfg7x0s226f56ja";
+    };
+    description = "Prboom libretro port";
+    license = gpl2;
+  }).override {
+    buildPhase = "make";
+  };
+
+  quicknes = (mkLibRetroCore rec {
+    core = "quicknes";
+    src = fetchRetro {
+      repo = "QuickNES_Core";
+      rev = "8613b48cee97f1472145bbafa76e543854b2bbd5";
+      sha256 = "18lizdb9zjlfhh8ibvmcscldlf3mw4aj8nds3pah68cd2lw170w1";
+    };
+    description = "QuickNES libretro port";
+    license = lgpl21Plus;
+  }).override {
+    buildPhase = "make";
+  };
+
+  reicast = (mkLibRetroCore rec {
+    core = "reicast";
+    src = fetchRetro {
+      repo = core + "-emulator";
+      rev = "40d4e8af2dd67a3f317c14224873c8ec0e1f9d11";
+      sha256 = "0d8wzpv7pcyh437gmvi439vim26wyrjmi5hj97wvyvggywjwrx8m";
+    };
+    description = "Reicast libretro port";
+    license = gpl2;
+    extraBuildInputs = [ libGLU_combined ];
+  }).override {
+    buildPhase = "make";
+  };
+
+  scummvm = (mkLibRetroCore rec {
+    core = "scummvm";
+    src = fetchRetro {
+      repo = core;
+      rev = "de8d7e58caa23f071ce9d1bc5133f45d16c3ff1c";
+      sha256 = "097i2dq3hw14hicsplrs36j1qa3r45vhzny5v4aw6qw4aj34hksy";
+    };
+    description = "Libretro port of ScummVM";
+    license = gpl2;
+    extraBuildInputs = [ fluidsynth libjpeg libvorbis libGLU_combined SDL ];
+  }).override {
+    buildPhase = "cd backends/platform/libretro/build && make";
+  };
+
+  snes9x = (mkLibRetroCore rec {
+    core = "snes9x";
+    src = fetchRetro {
+      repo = core;
+      rev = "db4bfaba3b0d5a067fe9aea323503656837a8d9a";
+      sha256 = "02f04ss45km32lp68diyfkix1gryx89qy8cc80189ipwnx80pgip";
+    };
+    description = "Port of SNES9x git to libretro";
+    license = "Non-commercial";
+  }).override {
+    buildPhase = "cd libretro && make";
+  };
+
+  snes9x-next = (mkLibRetroCore rec {
+    core = "snes9x-next";
+    src = fetchRetro {
+      repo = core;
+      rev = "b2a69de0df1eb39ed362806f9c9633f4544272af";
+      sha256 = "1vhgsrg9l562nincfvpj2h2dqkkblg1qmh0v47jqlqgmgl2b1zij";
+    };
+    description = "Optimized port/rewrite of SNES9x 1.52+ to Libretro";
+    license = "Non-commercial";
+  }).override {
+    buildPhase = ''
+      make -f Makefile.libretro
+      mv snes9x2010_libretro${stdenv.hostPlatform.extensions.sharedLibrary} snes9x_next_libretro${stdenv.hostPlatform.extensions.sharedLibrary}
+    '';
+  };
+
+  stella = (mkLibRetroCore rec {
+    core = "stella";
+    src = fetchRetro {
+      repo = core + "-libretro";
+      rev = "bbe65db0e344dcb38905586bd853076b65963e5a";
+      sha256 = "18r1yyfzvjq2hq04d94y37kzsq6aywh1aim69a3imk8kh46gwrh0";
+    };
+    description = "Port of Stella to libretro";
+    license = gpl2;
+  }).override {
+    buildPhase = "make";
+  };
+
+  vba-next = mkLibRetroCore rec {
+    core = "vba-next";
+    src = fetchRetro {
+      repo = core;
+      rev = "e7734756d228ea604f8fa872cea1bba987780791";
+      sha256 = "03s4rh7dbbhbfc4pfdvr9jcbxrp4ijg8yp49s1xhr7sxsblj2vpv";
+    };
+    description = "VBA-M libretro port with modifications for speed";
+    license = gpl2;
+  };
+
+  vba-m = (mkLibRetroCore rec {
+    core = "vbam";
+    src = fetchRetro {
+      repo = core + "-libretro";
+      rev = "1b82fc2d761f027567632692f787482d1e287ec2";
+      sha256 = "043djmqvh2grc25hwjw4b5kfx57b89ryp6fcl8v632sm35l3dd6z";
+    };
+    description = "vanilla VBA-M libretro port";
+    license = gpl2;
+  }).override {
+    buildPhase = "cd src/libretro && make";
+  };
+
+}
diff --git a/nixpkgs/pkgs/misc/emulators/retroarch/default.nix b/nixpkgs/pkgs/misc/emulators/retroarch/default.nix
new file mode 100644
index 000000000000..ee7ff114ec8f
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/retroarch/default.nix
@@ -0,0 +1,87 @@
+{ stdenv, fetchFromGitHub, which, pkgconfig, makeWrapper
+, ffmpeg, libGLU_combined, freetype, libxml2, python3
+, libobjc, AppKit, Foundation
+, alsaLib ? null
+, libpulseaudio ? null
+, libv4l ? null
+, libX11 ? null
+, libXdmcp ? null
+, libXext ? null
+, libXxf86vm ? null
+, SDL2 ? null
+, udev ? null
+, enableNvidiaCgToolkit ? false, nvidia_cg_toolkit ? null
+, withVulkan ? stdenv.isLinux, vulkan-loader ? null
+, fetchurl
+}:
+
+with stdenv.lib;
+
+let
+
+  # ibtool is closed source so we have to download the blob
+  osx-MainMenu = fetchurl {
+    url = "https://github.com/matthewbauer/RetroArch/raw/b146a9ac6b2b516652a7bf05a9db5a804eab323d/pkg/apple/OSX/en.lproj/MainMenu.nib";
+    sha256 = "13k1l628wy0rp6wxrpwr4g1m9c997d0q8ks50f8zhmh40l5j2sp8";
+  };
+
+in stdenv.mkDerivation rec {
+  name = "retroarch-bare-${version}";
+  version = "1.7.5";
+
+  src = fetchFromGitHub {
+    owner = "libretro";
+    repo = "RetroArch";
+    sha256 = "1jfpgl34jjxn3dvxd1kd564swkw7v98hnn562v998b7vllz3dxdm";
+    rev = "v${version}";
+  };
+
+  nativeBuildInputs = [ pkgconfig ]
+                      ++ optional withVulkan [ makeWrapper ];
+
+  buildInputs = [ ffmpeg freetype libxml2 libGLU_combined python3 SDL2 which ]
+                ++ optional enableNvidiaCgToolkit nvidia_cg_toolkit
+                ++ optional withVulkan [ vulkan-loader ]
+                ++ optionals stdenv.isDarwin [ libobjc AppKit Foundation ]
+                ++ optionals stdenv.isLinux [ alsaLib libpulseaudio libv4l libX11
+                                              libXdmcp libXext libXxf86vm udev ];
+
+  enableParallelBuilding = true;
+
+  postInstall = optionalString withVulkan ''
+    wrapProgram $out/bin/retroarch --prefix LD_LIBRARY_PATH ':' ${vulkan-loader}/lib
+  '' + optionalString stdenv.targetPlatform.isDarwin ''
+    EXECUTABLE_NAME=RetroArch
+    PRODUCT_NAME=RetroArch
+    MACOSX_DEPLOYMENT_TARGET=10.5
+    app=$out/Applications/$PRODUCT_NAME.app
+
+    install -D pkg/apple/OSX/Info.plist $app/Contents/Info.plist
+    echo "APPL????" > $app/Contents/PkgInfo
+    mkdir -p $app/Contents/MacOS
+    ln -s $out/bin/retroarch $app/Contents/MacOS/$EXECUTABLE_NAME
+
+    # Hack to fill in Info.plist template w/o using xcode
+    sed -i -e 's,''${EXECUTABLE_NAME}'",$EXECUTABLE_NAME," \
+           -e 's,''${MACOSX_DEPLOYMENT_TARGET}'",$MACOSX_DEPLOYMENT_TARGET," \
+           -e 's,''${PRODUCT_NAME}'",$PRODUCT_NAME," \
+           -e 's,''${PRODUCT_NAME:rfc1034identifier}'",$PRODUCT_NAME," \
+           $app/Contents/Info.plist
+
+    install -D ${osx-MainMenu} \
+               $app/Contents/Resources/en.lproj/MainMenu.nib
+    install -D pkg/apple/OSX/en.lproj/InfoPlist.strings \
+               $app/Contents/Resources/en.lproj/InfoPlist.strings
+    install -D media/retroarch.icns $app/Contents/Resources/retroarch.icns
+  '';
+
+  preFixup = "rm $out/bin/retroarch-cg2glsl";
+
+  meta = {
+    homepage = https://libretro.com;
+    description = "Multi-platform emulator frontend for libretro cores";
+    license = licenses.gpl3;
+    platforms = platforms.all;
+    maintainers = with maintainers; [ MP2E edwtjo matthewbauer ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/retroarch/kodi-advanced-launchers.nix b/nixpkgs/pkgs/misc/emulators/retroarch/kodi-advanced-launchers.nix
new file mode 100644
index 000000000000..6b708cccc8f8
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/retroarch/kodi-advanced-launchers.nix
@@ -0,0 +1,40 @@
+{ stdenv, pkgs, cores }:
+
+assert cores != [];
+
+with pkgs.lib;
+
+let
+
+  script = exec: ''
+    #!${stdenv.shell}
+    nohup sh -c "pkill -SIGTSTP kodi" &
+    # https://forum.kodi.tv/showthread.php?tid=185074&pid=1622750#pid1622750
+    nohup sh -c "sleep 10 && ${exec} '$@' -f;pkill -SIGCONT kodi"
+  '';
+  scriptSh = exec: pkgs.writeScript ("kodi-"+exec.name) (script exec.path);
+  execs = map (core: rec { name = core.core; path = core+"/bin/retroarch-"+name;}) cores;
+
+in
+
+stdenv.mkDerivation rec {
+  name = "kodi-retroarch-advanced-launchers-${version}";
+  version = "0.2";
+
+  dontBuild = true;
+
+  buildCommand = ''
+    mkdir -p $out/bin
+    ${stdenv.lib.concatMapStrings (exec: "ln -s ${scriptSh exec} $out/bin/kodi-${exec.name};") execs}
+  '';
+
+  meta = {
+    description = "Kodi retroarch advanced launchers";
+    longDescription = ''
+      These retroarch launchers are intended to be used with
+      advanced (emulation) launcher for Kodi since device input is
+      otherwise caught by both Kodi and the retroarch process.
+    '';
+    license = stdenv.lib.licenses.gpl3;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/retroarch/wrapper.nix b/nixpkgs/pkgs/misc/emulators/retroarch/wrapper.nix
new file mode 100644
index 000000000000..71ae168f1b23
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/retroarch/wrapper.nix
@@ -0,0 +1,43 @@
+{ stdenv, lib, makeWrapper, retroarch, cores }:
+
+let
+
+  p = builtins.parseDrvName retroarch.name;
+
+in
+
+stdenv.mkDerivation {
+  name = "retroarch-" + p.version;
+  version = p.version;
+
+  buildInputs = [ makeWrapper ];
+
+  buildCommand = ''
+    mkdir -p $out/lib
+    $(for coreDir in $cores
+    do
+      $(ln -s $coreDir/* $out/lib/.)
+    done)
+
+    ln -s -t $out ${retroarch}/share
+
+    if [ -d ${retroarch}/Applications ]; then
+      ln -s -t $out ${retroarch}/Applications
+    fi
+
+    makeWrapper ${retroarch}/bin/retroarch $out/bin/retroarch \
+      --suffix-each LD_LIBRARY_PATH ':' "$cores" \
+      --add-flags "-L $out/lib/" \
+  '';
+
+  cores = map (x: x + x.libretroCore) cores;
+  preferLocalBuild = true;
+
+  meta = with retroarch.meta; {
+    inherit license homepage platforms maintainers;
+    description = description
+                  + " (with cores: "
+                  + lib.concatStrings (lib.intersperse ", " (map (x: ""+x.name) cores))
+                  + ")";
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/retrofe/default.nix b/nixpkgs/pkgs/misc/emulators/retrofe/default.nix
new file mode 100644
index 000000000000..40c1fcc6fdef
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/retrofe/default.nix
@@ -0,0 +1,78 @@
+{ stdenv, fetchhg, cmake, glib, gst_all_1, makeWrapper, pkgconfig
+, python, SDL2, SDL2_image, SDL2_mixer, SDL2_ttf, sqlite, zlib
+}:
+
+stdenv.mkDerivation rec {
+  name = "retrofe-${version}";
+  version = "0.6.169";
+
+  src = fetchhg {
+    url = https://bitbucket.org/teamretro/retrofe;
+    rev = "8793e03";
+    sha256 = "0cvsg07ff0fdqh5zgiv2fs7s6c98hn150kpxmpw5fn6jilaszwkm";
+  };
+
+  nativeBuildInputs = [ cmake makeWrapper pkgconfig python ];
+
+  buildInputs = [
+    glib gst_all_1.gstreamer SDL2 SDL2_image SDL2_mixer SDL2_ttf sqlite zlib
+  ] ++ (with gst_all_1; [ gst-libav gst-plugins-base gst-plugins-good ]);
+
+  patches = [ ./include-paths.patch ];
+
+  configurePhase = ''
+    cmake RetroFE/Source -BRetroFE/Build -DCMAKE_BUILD_TYPE=Release \
+      -DVERSION_MAJOR=0 -DVERSION_MINOR=0 -DVERSION_BUILD=0 \
+      -DGSTREAMER_BASE_INCLUDE_DIRS='${gst_all_1.gst-plugins-base.dev}/include/gstreamer-1.0'
+  '';
+
+  buildPhase = ''
+    cmake --build RetroFE/Build
+    python Scripts/Package.py --os=linux --build=full
+  '';
+
+  installPhase = ''
+    mkdir -p $out/bin
+    mkdir -p $out/share/retrofe
+    cp -r Artifacts/linux/RetroFE $out/share/retrofe/example
+    mv $out/share/retrofe/example/retrofe $out/bin/
+
+    cat > $out/bin/retrofe-init << EOF
+    #!/bin/sh
+
+    echo "This will install retrofe's example files into this directory"
+    echo "Example files location: $out/share/retrofe/example/"
+
+    while true; do
+        read -p "Do you want to proceed? [yn] " yn
+        case \$yn in
+            [Yy]* ) cp -r --no-preserve=all $out/share/retrofe/example/* .; break;;
+            [Nn]* ) exit;;
+            * ) echo "Please answer with yes or no.";;
+        esac
+    done
+    EOF
+
+    chmod +x $out/bin/retrofe-init
+
+    runHook postInstall
+  '';
+
+  # retrofe will look for config files in its install path ($out/bin).
+  # When set it will use $RETROFE_PATH instead. Sadly this behaviour isn't
+  # documented well. To make it behave more like as expected it's set to
+  # $PWD by default here.
+  postInstall = ''
+    wrapProgram "$out/bin/retrofe" \
+      --prefix GST_PLUGIN_PATH : "$GST_PLUGIN_SYSTEM_PATH_1_0" \
+      --run 'export RETROFE_PATH=''${RETROFE_PATH:-$PWD}'
+  '';
+
+  meta = with stdenv.lib; {
+    description = "A frontend for arcade cabinets and media PCs";
+    homepage = http://retrofe.com;
+    license = licenses.gpl3Plus;
+    maintainers = with maintainers; [ hrdinka ];
+    platforms = with platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/retrofe/include-paths.patch b/nixpkgs/pkgs/misc/emulators/retrofe/include-paths.patch
new file mode 100644
index 000000000000..02eef2594ea6
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/retrofe/include-paths.patch
@@ -0,0 +1,11 @@
+diff -ur RetroFE.1/RetroFE/Source/CMakeLists.txt RetroFE.2/RetroFE/Source/CMakeLists.txt
+--- RetroFE.1/RetroFE/Source/CMakeLists.txt	2016-02-21 14:52:36.726070602 +0100
++++ RetroFE.2/RetroFE/Source/CMakeLists.txt	2016-02-21 14:38:43.036249029 +0100
+@@ -59,6 +59,7 @@
+ set(RETROFE_INCLUDE_DIRS

+ 	"${GLIB2_INCLUDE_DIRS}"

+ 	"${GSTREAMER_INCLUDE_DIRS}"

++	"${GSTREAMER_BASE_INCLUDE_DIRS}"

+ 	"${SDL2_INCLUDE_DIRS}"

+ 	"${SDL2_IMAGE_INCLUDE_DIRS}"

+ 	"${SDL2_MIXER_INCLUDE_DIRS}"

diff --git a/nixpkgs/pkgs/misc/emulators/rpcs3/default.nix b/nixpkgs/pkgs/misc/emulators/rpcs3/default.nix
new file mode 100644
index 000000000000..732a5971ed3c
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/rpcs3/default.nix
@@ -0,0 +1,53 @@
+{ stdenv, lib, fetchgit, cmake, pkgconfig, git                                                                      
+, qt5, openal, glew, vulkan-loader, libpng, ffmpeg, libevdev, python27                                              
+, pulseaudioSupport ? true, libpulseaudio                                                                           
+, waylandSupport ? true, wayland                                                                                    
+, alsaSupport ? true, alsaLib                                                                                       
+}:                                                                                                                  
+                                                                                                                    
+let                                                                                                                 
+  majorVersion = "0.0.5";                                                                                           
+  gitVersion = "6980-81e5f3b7f"; # echo $(git rev-list HEAD --count)-$(git rev-parse --short HEAD)                  
+in                                                                                                                  
+stdenv.mkDerivation rec {                                                                                           
+  name = "rpcs3-${version}";                                                                                        
+  version = "${majorVersion}-${gitVersion}";                                                                        
+                                                                                                                    
+  src = fetchgit {                                                                                                  
+    url = "https://github.com/RPCS3/rpcs3";                                                                         
+    rev = "81e5f3b7f299942f56bcfdde54edd09c722b32d8";                                                               
+    sha256 = "0czj6ga1nccqgcvi58sjnv1cc4k7qvwijp4warml463hpsmbd9r0";                                                
+  };                                                                                                                
+                                                                                                                    
+  preConfigure = ''                                                                                                 
+    cat > ./rpcs3/git-version.h <<EOF                                                                               
+    #define RPCS3_GIT_VERSION "${gitVersion}"                                                                       
+    #define RPCS3_GIT_BRANCH "HEAD"                                                                                 
+    #define RPCS3_GIT_VERSION_NO_UPDATE 1                                                                           
+    EOF
+  '';
+
+  cmakeFlags = [
+    "-DUSE_SYSTEM_LIBPNG=ON"
+    "-DUSE_SYSTEM_FFMPEG=ON"
+    "-DUSE_NATIVE_INSTRUCTIONS=OFF"
+  ];
+
+  nativeBuildInputs = [ cmake pkgconfig git ];
+
+  buildInputs = [
+    qt5.qtbase qt5.qtquickcontrols openal glew vulkan-loader libpng ffmpeg libevdev python27
+  ] ++ lib.optional pulseaudioSupport libpulseaudio
+    ++ lib.optional alsaSupport alsaLib
+    ++ lib.optional waylandSupport wayland;
+
+  enableParallelBuilding = true;
+
+  meta = with stdenv.lib; {
+    description = "PS3 emulator/debugger";
+    homepage = "https://rpcs3.net/";
+    maintainers = with maintainers; [ abbradar nocent ];
+    license = licenses.gpl2;
+    platforms = [ "x86_64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/snes9x-gtk/default.nix b/nixpkgs/pkgs/misc/emulators/snes9x-gtk/default.nix
new file mode 100644
index 000000000000..a58f95875ccf
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/snes9x-gtk/default.nix
@@ -0,0 +1,39 @@
+{ stdenv, fetchFromGitHub, autoreconfHook, wrapGAppsHook, intltool, pkgconfig
+, SDL2, zlib, gtk3, libxml2, libXv, epoxy, minizip, portaudio }:
+
+stdenv.mkDerivation rec {
+  name = "snes9x-gtk-${version}";
+  version = "1.57";
+
+  src = fetchFromGitHub {
+    owner = "snes9xgit";
+    repo = "snes9x";
+    rev = version;
+    sha256 = "1jcvj2l03b98iz6aq4x747vfz7i6h6j339z4brj4vz71s11vn31a";
+  };
+
+  enableParallelBuilding = true;
+  nativeBuildInputs = [ autoreconfHook wrapGAppsHook intltool pkgconfig ];
+  buildInputs = [ SDL2 zlib gtk3 libxml2 libXv epoxy minizip portaudio ];
+
+  preAutoreconf = ''
+    cd gtk
+    intltoolize
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = "http://www.snes9x.com";
+    description = "Super Nintendo Entertainment System (SNES) emulator";
+
+    longDescription = ''
+      Snes9x is a portable, freeware Super Nintendo Entertainment System (SNES)
+      emulator. It basically allows you to play most games designed for the SNES
+      and Super Famicom Nintendo game systems on your PC or Workstation; which
+      includes some real gems that were only ever released in Japan.
+    '';
+
+    license = licenses.lgpl2;
+    maintainers = with maintainers; [ qknight ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/stella/default.nix b/nixpkgs/pkgs/misc/emulators/stella/default.nix
new file mode 100644
index 000000000000..41ba5a3b2e61
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/stella/default.nix
@@ -0,0 +1,31 @@
+{ stdenv, fetchurl, pkgconfig, SDL2 }:
+
+with stdenv.lib;
+stdenv.mkDerivation rec {
+
+  name = "stella-${version}";
+  version = "4.6.1";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/project/stella/stella/${version}/${name}-src.tar.gz";
+    sha256 = "126jph21b70jlxapzmll8pq36i53lb304hbsiap25160vdqid4n1";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ SDL2 ];
+
+  meta = {
+    description = "An open-source Atari 2600 VCS emulator";
+    longDescription = ''
+    Stella is a multi-platform Atari 2600 VCS emulator released under
+    the GNU General Public License (GPL). Stella was originally
+    developed for Linux by Bradford W. Mott, and is currently
+    maintained by Stephen Anthony.
+    As of its 3.5 release, Stella is officially donationware. 
+    '';
+    homepage = http://stella.sourceforge.net/;
+    license = licenses.gpl2;
+    maintainers = [ maintainers.AndersonTorres ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/termtekst/default.nix b/nixpkgs/pkgs/misc/emulators/termtekst/default.nix
new file mode 100644
index 000000000000..8186aba1ee56
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/termtekst/default.nix
@@ -0,0 +1,36 @@
+{ lib, fetchFromGitHub, python3Packages, ncurses }:
+
+python3Packages.buildPythonApplication rec {
+  pname = "termtekst";
+  version = "1.0";
+
+  src = fetchFromGitHub {
+    owner = "zevv";
+    repo = pname;
+    rev = "v${version}";
+    sha256 = "1gm7j5d49a60wm7px82b76f610i8pl8ccz4r6qsz90z4mp3lyw9b";
+  };
+
+  propagatedBuildInputs = with python3Packages; [ ncurses requests ];
+
+  patchPhase = ''
+    substituteInPlace setup.py \
+      --replace "assert" "assert 1==1 #"
+    substituteInPlace src/tt \
+      --replace "locale.setlocale" "#locale.setlocale"
+    '';
+
+  meta = with lib; {
+    description = ''Console NOS Teletekst viewer in Python'';
+    longDescription = ''
+      Small Python app using curses to display Dutch NOS Teletekst on
+      the Linux console. The original Teletekst font includes 2x6
+      raster graphics glyphs which have no representation in unicode;
+      as a workaround the braille set is abused to approximate the
+      graphics.
+    '';
+    license = licenses.mit;
+    maintainers = with maintainers; [ leenaars ];
+    platforms = platforms.all;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/uae/default.nix b/nixpkgs/pkgs/misc/emulators/uae/default.nix
new file mode 100644
index 000000000000..318993d08b66
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/uae/default.nix
@@ -0,0 +1,25 @@
+{stdenv, fetchurl, pkgconfig, gtk2, alsaLib, SDL}:
+
+stdenv.mkDerivation rec {
+  name = "uae-0.8.29";
+
+  src = fetchurl {
+    url = "http://web.archive.org/web/20130905032631/http://www.amigaemulator.org/files/sources/develop/${name}.tar.bz2";
+    sha256 = "05s3cd1rd5a970s938qf4c2xm3l7f54g5iaqw56v8smk355m4qr4";
+  };
+
+  configureFlags = [ "--with-sdl" "--with-sdl-sound" "--with-sdl-gfx" "--with-alsa" ];
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ gtk2 alsaLib SDL ];
+
+  hardeningDisable = [ "format" ];
+
+  meta = {
+    description = "Ultimate/Unix/Unusable Amiga Emulator";
+    license = stdenv.lib.licenses.gpl2Plus;
+    homepage = http://web.archive.org/web/20130901222855/http://www.amigaemulator.org/;
+    maintainers = [ stdenv.lib.maintainers.sander ];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/vbam/default.nix b/nixpkgs/pkgs/misc/emulators/vbam/default.nix
new file mode 100644
index 000000000000..59f0252259cc
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/vbam/default.nix
@@ -0,0 +1,56 @@
+{ stdenv
+, cairo
+, cmake
+, fetchFromGitHub
+, ffmpeg
+, gettext
+, libGLU_combined
+, openal
+, pkgconfig
+, SDL2
+, sfml
+, zip
+, zlib
+}:
+
+stdenv.mkDerivation rec {
+  name = "visualboyadvance-m-${version}";
+  version = "2.1.0";
+  src = fetchFromGitHub {
+    owner = "visualboyadvance-m";
+    repo = "visualboyadvance-m";
+    rev = "v${version}";
+    sha256 = "1dppfvy24rgg3h84gv33l1y7zznkv3zxn2hf98w85pca6k1y2afz";
+  };
+
+  buildInputs = [
+    cairo
+    cmake
+    ffmpeg
+    gettext
+    libGLU_combined
+    openal
+    pkgconfig
+    SDL2
+    sfml
+    zip
+    zlib
+  ];
+
+  cmakeFlags = [
+    "-DCMAKE_BUILD_TYPE='Release'"
+    "-DENABLE_FFMPEG='true'"
+    "-DENABLE_LINK='true'"
+    "-DSYSCONFDIR=etc"
+    "-DENABLE_WX='false'"
+    "-DENABLE_SDL='true'"
+  ];
+
+  meta = {
+    description = "A merge of the original Visual Boy Advance forks";
+    license = stdenv.lib.licenses.gpl2;
+    maintainers = [ stdenv.lib.maintainers.lassulus ];
+    homepage = http://vba-m.com/;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/vice/default.nix b/nixpkgs/pkgs/misc/emulators/vice/default.nix
new file mode 100644
index 000000000000..7cf4faf55cd7
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/vice/default.nix
@@ -0,0 +1,53 @@
+{ stdenv, fetchurl, bison, flex, perl, libpng, giflib, libjpeg, alsaLib, readline, libGLU_combined, libXaw
+, pkgconfig, gtk2, SDL, autoreconfHook, makeDesktopItem
+}:
+
+stdenv.mkDerivation rec {
+  name = "vice-3.1";
+
+  src = fetchurl {
+    url = mirror://sourceforge/vice-emu/vice-3.1.tar.gz;
+    sha256 = "0h0jbml02s2a36hr78dxv1zshmfhxp1wadpcdl09aq416fb1bf1y";
+  };
+
+  buildInputs = [ bison flex perl libpng giflib libjpeg alsaLib readline libGLU_combined
+    pkgconfig gtk2 SDL autoreconfHook libXaw ];
+  dontDisableStatic = true;
+  configureFlags = [ "--enable-fullscreen --enable-gnomeui" ];
+
+  desktopItem = makeDesktopItem {
+    name = "vice";
+    exec = "x64";
+    comment = "Commodore 64 emulator";
+    desktopName = "VICE";
+    genericName = "Commodore 64 emulator";
+    categories = "Application;Emulator;";
+  };
+
+  preBuild = ''
+    for i in src/resid src/resid-dtv
+    do
+        mkdir -pv $i/src
+        ln -sv ../../wrap-u-ar.sh $i/src
+    done
+  '';
+  patchPhase = ''
+    # Disable font-cache update
+    sed -i -e "s|install: install-data-am|install-no: install-data-am|" data/fonts/Makefile.am
+  '';
+
+  #NIX_LDFLAGS = "-lX11 -L${libX11}/lib";
+
+  postInstall = ''
+    mkdir -p $out/share/applications
+    cp ${desktopItem}/share/applications/* $out/share/applications
+  '';
+
+  meta = {
+    description = "Commodore 64, 128 and other emulators";
+    homepage = http://www.viceteam.org;
+    license = stdenv.lib.licenses.gpl2Plus;
+    maintainers = [ stdenv.lib.maintainers.sander ];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/wine/base.nix b/nixpkgs/pkgs/misc/emulators/wine/base.nix
new file mode 100644
index 000000000000..94cf4a774569
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/wine/base.nix
@@ -0,0 +1,122 @@
+{ stdenv, lib, pkgArches,
+  name, version, src, monos, geckos, platforms,
+  pkgconfig, fontforge, makeWrapper, flex, bison,
+  supportFlags,
+  buildScript ? null, configureFlags ? []
+}:
+
+with import ./util.nix { inherit lib; };
+
+stdenv.mkDerivation ((lib.optionalAttrs (! isNull buildScript) {
+  builder = buildScript;
+}) // rec {
+  inherit name src configureFlags;
+
+  nativeBuildInputs = [
+    pkgconfig fontforge makeWrapper flex bison
+  ];
+
+  buildInputs = toBuildInputs pkgArches (with supportFlags; (pkgs:
+  [ pkgs.freetype ]
+  ++ lib.optional stdenv.isLinux         pkgs.libcap
+  ++ lib.optional pngSupport             pkgs.libpng
+  ++ lib.optional jpegSupport            pkgs.libjpeg
+  ++ lib.optional cupsSupport            pkgs.cups
+  ++ lib.optional colorManagementSupport pkgs.lcms2
+  ++ lib.optional gettextSupport         pkgs.gettext
+  ++ lib.optional dbusSupport            pkgs.dbus
+  ++ lib.optional mpg123Support          pkgs.mpg123
+  ++ lib.optional openalSupport          pkgs.openal
+  ++ lib.optional cairoSupport           pkgs.cairo
+  ++ lib.optional tiffSupport            pkgs.libtiff
+  ++ lib.optional odbcSupport            pkgs.unixODBC
+  ++ lib.optional netapiSupport          pkgs.samba4
+  ++ lib.optional cursesSupport          pkgs.ncurses
+  ++ lib.optional vaSupport              pkgs.libva
+  ++ lib.optional pcapSupport            pkgs.libpcap
+  ++ lib.optional v4lSupport             pkgs.libv4l
+  ++ lib.optional saneSupport            pkgs.sane-backends
+  ++ lib.optional gsmSupport             pkgs.gsm
+  ++ lib.optional gphoto2Support         pkgs.libgphoto2
+  ++ lib.optional ldapSupport            pkgs.openldap
+  ++ lib.optional fontconfigSupport      pkgs.fontconfig
+  ++ lib.optional alsaSupport            pkgs.alsaLib
+  ++ lib.optional pulseaudioSupport      pkgs.libpulseaudio
+  ++ lib.optional xineramaSupport        pkgs.xorg.libXinerama
+  ++ lib.optional udevSupport            pkgs.udev
+  ++ lib.optional vulkanSupport          pkgs.vulkan-loader
+  ++ lib.optional sdlSupport             pkgs.SDL2
+  ++ lib.optionals gstreamerSupport      (with pkgs.gst_all_1; [ gstreamer gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly gst-libav ])
+  ++ lib.optionals gtkSupport    [ pkgs.gtk3 pkgs.glib ]
+  ++ lib.optionals openclSupport [ pkgs.opencl-headers pkgs.ocl-icd ]
+  ++ lib.optionals xmlSupport    [ pkgs.libxml2 pkgs.libxslt ]
+  ++ lib.optionals tlsSupport    [ pkgs.openssl pkgs.gnutls ]
+  ++ lib.optionals openglSupport [ pkgs.libGLU_combined pkgs.mesa_noglu.osmesa pkgs.libdrm ]
+  ++ lib.optionals stdenv.isDarwin (with pkgs.buildPackages.darwin.apple_sdk.frameworks; [
+     CoreServices Foundation ForceFeedback AppKit OpenGL IOKit DiskArbitration Security
+     ApplicationServices AudioToolbox CoreAudio AudioUnit CoreMIDI OpenAL OpenCL Cocoa Carbon
+  ])
+  ++ lib.optionals stdenv.isLinux  (with pkgs.xorg; [
+     libXi libXcursor libXrandr libXrender libXxf86vm libXcomposite libXext
+  ])
+  ++ [ pkgs.xorg.libX11 ]));
+
+  # Wine locates a lot of libraries dynamically through dlopen().  Add
+  # them to the RPATH so that the user doesn't have to set them in
+  # LD_LIBRARY_PATH.
+  NIX_LDFLAGS = map (path: "-rpath " + path) (
+      map (x: "${lib.getLib x}/lib") ([ stdenv.cc.cc ] ++ buildInputs)
+      # libpulsecommon.so is linked but not found otherwise
+      ++ lib.optionals supportFlags.pulseaudioSupport (map (x: "${lib.getLib x}/lib/pulseaudio")
+          (toBuildInputs pkgArches (pkgs: [ pkgs.libpulseaudio ])))
+    );
+
+  # Don't shrink the ELF RPATHs in order to keep the extra RPATH
+  # elements specified above.
+  dontPatchELF = true;
+
+  # Disable stripping to avoid breaking placeholder DLLs/EXEs.
+  # Symptoms of broken placeholders are: when the wineprefix is created
+  # drive_c/windows/system32 will only contain a few files instead of
+  # hundreds, there will be an error about winemenubuilder and MountMgr
+  # on startup of Wine, and the Drives tab in winecfg will show an error.
+  dontStrip = true;
+
+  ## FIXME
+  # Add capability to ignore known failing tests
+  # and enable doCheck
+  doCheck = false;
+
+  postInstall = let
+    links = prefix: pkg: "ln -s ${pkg} $out/${prefix}/${pkg.name}";
+  in ''
+    mkdir -p $out/share/wine/gecko $out/share/wine/mono/
+    ${lib.strings.concatStringsSep "\n"
+          ((map (links "share/wine/gecko") geckos)
+        ++ (map (links "share/wine/mono")  monos))}
+  '' + lib.optionalString supportFlags.gstreamerSupport ''
+    for i in wine ; do
+      if [ -e "$out/bin/$i" ]; then
+        wrapProgram "$out/bin/$i" \
+          --argv0 "" \
+          --prefix GST_PLUGIN_SYSTEM_PATH_1_0 ":" "$GST_PLUGIN_SYSTEM_PATH_1_0"
+      fi
+    done
+  '';
+
+  enableParallelBuilding = true;
+
+  # https://bugs.winehq.org/show_bug.cgi?id=43530
+  # https://github.com/NixOS/nixpkgs/issues/31989
+  hardeningDisable = [ "bindnow" ]
+    ++ lib.optional (stdenv.hostPlatform.isDarwin) "fortify";
+
+  passthru = { inherit pkgArches; };
+  meta = {
+    inherit version platforms;
+    homepage = http://www.winehq.org/;
+    license = "LGPL";
+    description = "An Open Source implementation of the Windows API on top of X, OpenGL, and Unix";
+    maintainers = with stdenv.lib.maintainers; [ avnik raskin bendlas ];
+  };
+})
diff --git a/nixpkgs/pkgs/misc/emulators/wine/builder-wow.sh b/nixpkgs/pkgs/misc/emulators/wine/builder-wow.sh
new file mode 100644
index 000000000000..1aad9fe20c78
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/wine/builder-wow.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+## build described at http://wiki.winehq.org/Wine64
+
+source $stdenv/setup
+
+unpackPhase
+cd $TMP/$sourceRoot
+patchPhase
+
+configureScript=$TMP/$sourceRoot/configure
+mkdir -p $TMP/wine-wow $TMP/wine64
+
+cd $TMP/wine64
+sourceRoot=`pwd`
+configureFlags="--enable-win64"
+configurePhase
+buildPhase
+# checkPhase
+
+cd $TMP/wine-wow
+sourceRoot=`pwd`
+configureFlags="--with-wine64=../wine64"
+configurePhase
+buildPhase
+# checkPhase
+
+eval "$preInstall"
+cd $TMP/wine-wow && make install
+cd $TMP/wine64 && make install
+eval "$postInstall"
+fixupPhase
diff --git a/nixpkgs/pkgs/misc/emulators/wine/default.nix b/nixpkgs/pkgs/misc/emulators/wine/default.nix
new file mode 100644
index 000000000000..6ecca6c25032
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/wine/default.nix
@@ -0,0 +1,67 @@
+## Configuration:
+# Control you default wine config in nixpkgs-config:
+# wine = {
+#   release = "stable"; # "stable", "unstable", "staging"
+#   build = "wineWow"; # "wine32", "wine64", "wineWow"
+# };
+# Make additional configurations on demand:
+# wine.override { wineBuild = "wine32"; wineRelease = "staging"; };
+{ lib, stdenv, callPackage,
+  wineRelease ? "stable",
+  wineBuild ? if stdenv.hostPlatform.system == "x86_64-linux" then "wineWow" else "wine32",
+  libtxc_dxtn_Name ? "libtxc_dxtn_s2tc",
+  pngSupport ? false,
+  jpegSupport ? false,
+  tiffSupport ? false,
+  gettextSupport ? false,
+  fontconfigSupport ? false,
+  alsaSupport ? false,
+  gtkSupport ? false,
+  openglSupport ? false,
+  tlsSupport ? false,
+  gstreamerSupport ? false,
+  cupsSupport ? false,
+  colorManagementSupport ? false,
+  dbusSupport ? false,
+  mpg123Support ? false,
+  openalSupport ? false,
+  openclSupport ? false,
+  cairoSupport ? false,
+  odbcSupport ? false,
+  netapiSupport ? false,
+  cursesSupport ? false,
+  vaSupport ? false,
+  pcapSupport ? false,
+  v4lSupport ? false,
+  saneSupport ? false,
+  gsmSupport ? false,
+  gphoto2Support ? false,
+  ldapSupport ? false,
+  pulseaudioSupport ? false,
+  udevSupport ? false,
+  xineramaSupport ? false,
+  xmlSupport ? false,
+  vulkanSupport ? false,
+  sdlSupport ? false,
+}:
+
+let wine-build = build: release:
+      lib.getAttr build (callPackage ./packages.nix {
+        wineRelease = release;
+        supportFlags = {
+          inherit pngSupport jpegSupport cupsSupport colorManagementSupport gettextSupport
+                  dbusSupport mpg123Support openalSupport cairoSupport tiffSupport odbcSupport
+                  netapiSupport cursesSupport vaSupport pcapSupport v4lSupport saneSupport
+                  gsmSupport gphoto2Support ldapSupport fontconfigSupport alsaSupport
+                  pulseaudioSupport xineramaSupport gtkSupport openclSupport xmlSupport tlsSupport
+                  openglSupport gstreamerSupport udevSupport vulkanSupport sdlSupport;
+        };
+      });
+
+in if wineRelease == "staging" then
+  callPackage ./staging.nix {
+    inherit libtxc_dxtn_Name;
+    wineUnstable = wine-build wineBuild "unstable";
+  }
+else
+  wine-build wineBuild wineRelease
diff --git a/nixpkgs/pkgs/misc/emulators/wine/packages.nix b/nixpkgs/pkgs/misc/emulators/wine/packages.nix
new file mode 100644
index 000000000000..3ea60e62c665
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/wine/packages.nix
@@ -0,0 +1,35 @@
+{ stdenv_32bit, lib, pkgs, pkgsi686Linux, callPackage,
+  wineRelease ? "stable",
+  supportFlags
+}:
+
+let src = lib.getAttr wineRelease (callPackage ./sources.nix {});
+in with src; {
+  wine32 = pkgsi686Linux.callPackage ./base.nix {
+    name = "wine-${version}";
+    inherit src version supportFlags;
+    pkgArches = [ pkgsi686Linux ];
+    geckos = [ gecko32 ];
+    monos =  [ mono ];
+    platforms = [ "i686-linux" "x86_64-linux" ];
+  };
+  wine64 = callPackage ./base.nix {
+    name = "wine64-${version}";
+    inherit src version supportFlags;
+    pkgArches = [ pkgs ];
+    geckos = [ gecko64 ];
+    monos =  [ mono ];
+    configureFlags = [ "--enable-win64" ];
+    platforms = [ "x86_64-linux" "x86_64-darwin" ];
+  };
+  wineWow = callPackage ./base.nix {
+    name = "wine-wow-${version}";
+    inherit src version supportFlags;
+    stdenv = stdenv_32bit;
+    pkgArches = [ pkgs pkgsi686Linux ];
+    geckos = [ gecko32 gecko64 ];
+    monos =  [ mono ];
+    buildScript = ./builder-wow.sh;
+    platforms = [ "x86_64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/wine/sources.nix b/nixpkgs/pkgs/misc/emulators/wine/sources.nix
new file mode 100644
index 000000000000..8b80dd838aea
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/wine/sources.nix
@@ -0,0 +1,65 @@
+{ pkgs ? import <nixpkgs> {} }:
+## we default to importing <nixpkgs> here, so that you can use
+## a simple shell command to insert new sha256's into this file
+## e.g. with emacs C-u M-x shell-command
+##
+##     nix-prefetch-url sources.nix -A {stable{,.mono,.gecko64,.gecko32}, unstable, staging, winetricks}
+
+# here we wrap fetchurl and fetchFromGitHub, in order to be able to pass additional args around it
+let fetchurl = args@{url, sha256, ...}:
+  pkgs.fetchurl { inherit url sha256; } // args;
+    fetchFromGitHub = args@{owner, repo, rev, sha256, ...}:
+  pkgs.fetchFromGitHub { inherit owner repo rev sha256; } // args;
+in rec {
+
+  stable = fetchurl rec {
+    version = "3.0.4";
+    url = "https://dl.winehq.org/wine/source/3.0/wine-${version}.tar.xz";
+    sha256 = "037vlrk80lagy362w7500i2ldwvdwsadrknajzi67cvxpvnqhnnl";
+
+    ## see http://wiki.winehq.org/Gecko
+    gecko32 = fetchurl rec {
+      version = "2.47";
+      url = "http://dl.winehq.org/wine/wine-gecko/${version}/wine_gecko-${version}-x86.msi";
+      sha256 = "0fk4fwb4ym8xn0i5jv5r5y198jbpka24xmxgr8hjv5b3blgkd2iv";
+    };
+    gecko64 = fetchurl rec {
+      version = "2.47";
+      url = "http://dl.winehq.org/wine/wine-gecko/${version}/wine_gecko-${version}-x86_64.msi";
+      sha256 = "0zaagqsji6zaag92fqwlasjs8v9hwjci5c2agn9m7a8fwljylrf5";
+    };
+
+    ## see http://wiki.winehq.org/Mono
+    mono = fetchurl rec {
+      version = "4.7.3";
+      url = "http://dl.winehq.org/wine/wine-mono/${version}/wine-mono-${version}.msi";
+      sha256 = "0fkd22v2vm3ml76x1ngg42byvmry24xb92vpl4j84zhw6wbq0jnj";
+    };
+  };
+
+  unstable = fetchurl rec {
+    # NOTE: Don't forget to change the SHA256 for staging as well.
+    version = "4.0-rc2";
+    url = "https://dl.winehq.org/wine/source/4.0/wine-${version}.tar.xz";
+    sha256 = "0apqavsk1y56b6c4zkjpi014xwgn6gjg6pzjx94qy4nfr1gz63n4";
+    inherit (stable) mono gecko32 gecko64;
+  };
+
+  staging = fetchFromGitHub rec {
+    # https://github.com/wine-staging/wine-staging/releases
+    inherit (unstable) version;
+    sha256 = "1vqvy44h9rwfx32pad831kdyhazn68s8r14w8765ly42rixc6dgj";
+    owner = "wine-staging";
+    repo = "wine-staging";
+    rev = "v${version}";
+  };
+
+  winetricks = fetchFromGitHub rec {
+    # https://github.com/Winetricks/winetricks/releases
+    version = "20181203";
+    sha256 = "1as5h5xibpplm619b1i73g974p96q2jnd7fqm28xj3zkqy7qjdm3";
+    owner = "Winetricks";
+    repo = "winetricks";
+    rev = version;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/wine/staging.nix b/nixpkgs/pkgs/misc/emulators/wine/staging.nix
new file mode 100644
index 000000000000..5264e66279f7
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/wine/staging.nix
@@ -0,0 +1,24 @@
+{ stdenv, callPackage, wineUnstable, libtxc_dxtn_Name }:
+
+with callPackage ./util.nix {};
+
+let patch = (callPackage ./sources.nix {}).staging;
+    build-inputs = pkgNames: extra:
+      (mkBuildInputs wineUnstable.pkgArches pkgNames) ++ extra;
+in assert (builtins.parseDrvName wineUnstable.name).version == patch.version;
+
+stdenv.lib.overrideDerivation wineUnstable (self: {
+  buildInputs = build-inputs [ "perl" "utillinux" "autoconf" libtxc_dxtn_Name ] self.buildInputs;
+
+  name = "${self.name}-staging";
+
+  postPatch = self.postPatch or "" + ''
+    patchShebangs tools
+    cp -r ${patch}/patches .
+    chmod +w patches
+    cd patches
+    patchShebangs gitapply.sh
+    ./patchinstall.sh DESTDIR="$PWD/.." --all
+    cd ..
+  '';
+})
diff --git a/nixpkgs/pkgs/misc/emulators/wine/util.nix b/nixpkgs/pkgs/misc/emulators/wine/util.nix
new file mode 100644
index 000000000000..b90a68e72df5
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/wine/util.nix
@@ -0,0 +1,9 @@
+{ lib }:
+rec {
+  toPackages = pkgNames: pkgs:
+    map (pn: lib.getAttr pn pkgs) pkgNames;
+  toBuildInputs = pkgArches: archPkgs:
+    lib.concatLists (map archPkgs pkgArches);  
+  mkBuildInputs = pkgArches: pkgNames:
+    toBuildInputs pkgArches (toPackages pkgNames);
+}
diff --git a/nixpkgs/pkgs/misc/emulators/wine/winetricks.nix b/nixpkgs/pkgs/misc/emulators/wine/winetricks.nix
new file mode 100644
index 000000000000..76606edf53c3
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/wine/winetricks.nix
@@ -0,0 +1,32 @@
+{ stdenv, callPackage, wine, perl, which, coreutils, zenity, curl
+, cabextract, unzip, p7zip, gnused, gnugrep, bash } :
+
+stdenv.mkDerivation rec {
+  name = "winetricks-${src.version}";
+
+  src = (callPackage ./sources.nix {}).winetricks;
+
+  buildInputs = [ perl which ];
+
+  # coreutils is for sha1sum
+  pathAdd = stdenv.lib.concatMapStringsSep ":" (x: x + "/bin")
+    [ wine perl which coreutils zenity curl cabextract unzip p7zip gnused gnugrep bash ];
+
+  makeFlags = [ "PREFIX=$(out)" ];
+
+  doCheck = false; # requires "bashate"
+
+  postInstall = ''
+    sed -i \
+      -e '2i PATH="${pathAdd}:$PATH"' \
+      "$out/bin/winetricks"
+  '';
+
+  meta = {
+    description = "A script to install DLLs needed to work around problems in Wine";
+    license = stdenv.lib.licenses.lgpl21;
+    homepage = https://github.com/Winetricks/winetricks;
+    maintainers = with stdenv.lib.maintainers; [ the-kenny ];
+    platforms = with stdenv.lib.platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/wxmupen64plus/default.nix b/nixpkgs/pkgs/misc/emulators/wxmupen64plus/default.nix
new file mode 100644
index 000000000000..e63d27ec4039
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/wxmupen64plus/default.nix
@@ -0,0 +1,30 @@
+{ stdenv, fetchurl, python, wxGTK29, mupen64plus, SDL, libX11, libGLU_combined
+, wafHook }:
+
+stdenv.mkDerivation {
+  name = "wxmupen64plus-0.3";
+  src = fetchurl {
+    url = "https://bitbucket.org/auria/wxmupen64plus/get/0.3.tar.bz2";
+    sha256 = "1mnxi4k011dd300k35li2p6x4wccwi6im21qz8dkznnz397ps67c";
+  };
+
+  nativeBuildInputs = [ wafHook ];
+  buildInputs = [ python wxGTK29 SDL libX11 libGLU_combined ];
+
+  preConfigure = ''
+    tar xf ${mupen64plus.src}
+    APIDIR=$(eval echo `pwd`/mupen64plus*/source/mupen64plus-core/src/api)
+    export CXXFLAGS="-I${libX11.dev}/include/X11 -DLIBDIR=\\\"${mupen64plus}/lib/\\\""
+    export LDFLAGS="-lwx_gtk2u_adv-2.9"
+
+    configureFlagsArray+=("--mupenapi=$APIDIR" "--wxconfig=`type -P wx-config`")
+  '';
+
+  NIX_CFLAGS_COMPILE = "-fpermissive";
+
+  meta = {
+    description = "GUI for the Mupen64Plus 2.0 emulator";
+    license = stdenv.lib.licenses.gpl2Plus;
+    homepage = https://bitbucket.org/auria/wxmupen64plus/wiki/Home;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/xcpc/default.nix b/nixpkgs/pkgs/misc/emulators/xcpc/default.nix
new file mode 100644
index 000000000000..5eb6e3b160ef
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/xcpc/default.nix
@@ -0,0 +1,22 @@
+{ stdenv, fetchurl, libdsk, pkgconfig, glib, libXaw, libX11, libXext, lesstif }:
+
+stdenv.mkDerivation rec {
+  version = "20070122";
+  name = "xcpc-${version}";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/xcpc/${name}.tar.gz";
+    sha256 = "0hxsbhmyzyyrlidgg0q8izw55q0z40xrynw5a1c3frdnihj9jf7n";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ glib libdsk libXaw libX11 libXext lesstif ];
+
+  meta = with stdenv.lib; {
+    description = "A portable Amstrad CPC 464/664/6128 emulator written in C";
+    homepage = https://www.xcpc-emulator.net;
+    license = licenses.gpl2Plus;
+    maintainers = [ maintainers.genesis ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/yabause/0001-Fixes-for-Qt-5.11-upgrade.patch b/nixpkgs/pkgs/misc/emulators/yabause/0001-Fixes-for-Qt-5.11-upgrade.patch
new file mode 100644
index 000000000000..43539ef4ca58
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/yabause/0001-Fixes-for-Qt-5.11-upgrade.patch
@@ -0,0 +1,67 @@
+From 3140afd6fb7dad7a25296526a71b005fb9eae048 Mon Sep 17 00:00:00 2001
+From: Samuel Dionne-Riel <samuel@dionne-riel.com>
+Date: Sat, 8 Sep 2018 00:44:08 -0400
+Subject: [PATCH] Fixes for Qt 5.11 upgrade
+
+---
+ src/qt/ui/UICheatRaw.cpp | 2 --
+ src/qt/ui/UICheatRaw.h   | 2 +-
+ src/qt/ui/UICheats.cpp   | 2 ++
+ src/qt/ui/UIHexInput.h   | 2 ++
+ 4 files changed, 5 insertions(+), 3 deletions(-)
+
+diff --git a/src/qt/ui/UICheatRaw.cpp b/src/qt/ui/UICheatRaw.cpp
+index 4ad82d77..3f78486b 100755
+--- a/src/qt/ui/UICheatRaw.cpp
++++ b/src/qt/ui/UICheatRaw.cpp
+@@ -20,8 +20,6 @@
+ #include "UIHexInput.h"

+ #include "../QtYabause.h"

+ 

+-#include <QButtonGroup>

+-

+ UICheatRaw::UICheatRaw( QWidget* p )

+ 	: QDialog( p )

+ {

+diff --git a/src/qt/ui/UICheatRaw.h b/src/qt/ui/UICheatRaw.h
+index d97b429d..20318c67 100755
+--- a/src/qt/ui/UICheatRaw.h
++++ b/src/qt/ui/UICheatRaw.h
+@@ -21,7 +21,7 @@
+ 

+ #include "ui_UICheatRaw.h"

+ 

+-class QButtonGroup;

++#include <QButtonGroup>

+ 

+ class UICheatRaw : public QDialog, public Ui::UICheatRaw

+ {

+diff --git a/src/qt/ui/UICheats.cpp b/src/qt/ui/UICheats.cpp
+index c6027972..44d341c3 100755
+--- a/src/qt/ui/UICheats.cpp
++++ b/src/qt/ui/UICheats.cpp
+@@ -21,6 +21,8 @@
+ #include "UICheatRaw.h"
+ #include "../CommonDialogs.h"
+ 
++#include <QButtonGroup>
++
+ UICheats::UICheats( QWidget* p )
+ 	: QDialog( p )
+ {
+diff --git a/src/qt/ui/UIHexInput.h b/src/qt/ui/UIHexInput.h
+index f333b016..4bd8aed4 100644
+--- a/src/qt/ui/UIHexInput.h
++++ b/src/qt/ui/UIHexInput.h
+@@ -22,6 +22,8 @@
+ #include "ui_UIHexInput.h"

+ #include "../QtYabause.h"

+ 

++#include <QValidator>

++

+ class HexValidator : public QValidator

+ {

+    Q_OBJECT

+-- 
+2.16.4
+
diff --git a/nixpkgs/pkgs/misc/emulators/yabause/default.nix b/nixpkgs/pkgs/misc/emulators/yabause/default.nix
new file mode 100644
index 000000000000..a2d462fd990e
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/yabause/default.nix
@@ -0,0 +1,36 @@
+{ stdenv, fetchurl, cmake, pkgconfig, qtbase, qt5, libGLU_combined
+, freeglut ? null, openal ? null, SDL2 ? null }:
+
+stdenv.mkDerivation rec {
+  name = "yabause-${version}";
+  version = "0.9.15";
+
+  src = fetchurl {
+    url = "https://download.tuxfamily.org/yabause/releases/${version}/${name}.tar.gz";
+    sha256 = "1cn2rjjb7d9pkr4g5bqz55vd4pzyb7hg94cfmixjkzzkw0zw8d23";
+  };
+
+  nativeBuildInputs = [ cmake pkgconfig ];
+  buildInputs = [ qtbase qt5.qtmultimedia libGLU_combined freeglut openal SDL2 ];
+
+  patches = [
+    ./linkage-rwx-linux-elf.patch
+    # Fixes derived from
+    # https://github.com/Yabause/yabause/commit/06a816c032c6f7fd79ced6e594dd4b33571a0e73
+    ./0001-Fixes-for-Qt-5.11-upgrade.patch
+  ];
+
+  cmakeFlags = [
+    "-DYAB_NETWORK=ON"
+    "-DYAB_OPTIMIZED_DMA=ON"
+    "-DYAB_PORTS=qt"
+  ] ;
+
+  meta = with stdenv.lib; {
+    description = "An open-source Sega Saturn emulator";
+    homepage = https://yabause.org/;
+    license = licenses.gpl2Plus;
+    maintainers = with maintainers; [ AndersonTorres ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/misc/emulators/yabause/linkage-rwx-linux-elf.patch b/nixpkgs/pkgs/misc/emulators/yabause/linkage-rwx-linux-elf.patch
new file mode 100644
index 000000000000..bb0491b373f8
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/yabause/linkage-rwx-linux-elf.patch
@@ -0,0 +1,20 @@
+--- a/src/sh2_dynarec/linkage_x64.s	2013-03-11 20:29:53.112870900 +0100
++++ b/src/sh2_dynarec/linkage_x64.s	2013-03-11 20:31:48.856778600 +0100
+@@ -747,3 +747,7 @@ breakpoint:
+ 	ret
+ 	/* Set breakpoint here for debugging */
+ 	.size	breakpoint, .-breakpoint
++
++#if defined(__linux__) && defined(__ELF__)
++.section .note.GNU-stack,"",%progbits
++#endif
+--- a/src/sh2_dynarec/linkage_x86.s	2013-03-11 20:30:08.157693100 +0100
++++ b/src/sh2_dynarec/linkage_x86.s	2013-03-11 20:32:30.993310600 +0100
+@@ -743,3 +743,7 @@ breakpoint:
+ 	ret
+ 	/* Set breakpoint here for debugging */
+ 	.size	breakpoint, .-breakpoint
++
++#if defined(__linux__) && defined(__ELF__)
++.section .note.GNU-stack,"",%progbits
++#endif
diff --git a/nixpkgs/pkgs/misc/emulators/zsnes/default.nix b/nixpkgs/pkgs/misc/emulators/zsnes/default.nix
new file mode 100644
index 000000000000..1ea8d7e68d3c
--- /dev/null
+++ b/nixpkgs/pkgs/misc/emulators/zsnes/default.nix
@@ -0,0 +1,63 @@
+{stdenv, fetchFromGitHub, nasm, SDL, zlib, libpng, ncurses, libGLU_combined
+, makeDesktopItem }:
+
+let
+  desktopItem = makeDesktopItem {
+    name = "zsnes";
+    exec = "zsnes";
+    icon = "zsnes";
+    comment = "A SNES emulator";
+    desktopName = "zsnes";
+    genericName = "zsnes";
+    categories = "Game;";
+  };
+
+in stdenv.mkDerivation {
+  name = "zsnes-1.51";
+
+  src = fetchFromGitHub {
+    owner = "emillon";
+    repo = "zsnes";
+    rev = "fc160b2538738995f600f8405d23a66b070dac02";
+    sha256 = "1gy79d5wdaacph0cc1amw7mqm7i0716n6mvav16p1svi26iz193v";
+  };
+
+  buildInputs = [ nasm SDL zlib libpng ncurses libGLU_combined ];
+
+  prePatch = ''
+    for i in $(cat debian/patches/series); do
+      echo "applying $i"
+      patch -p1 < "debian/patches/$i"
+    done
+  '';
+
+  preConfigure = ''
+    cd src
+    sed -i "/^STRIP/d" configure
+    sed -i "/\$STRIP/d" configure
+  '';
+
+  configureFlags = [ "--enable-release" ];
+
+  postInstall = ''
+    function installIcon () {
+        mkdir -p $out/share/icons/hicolor/$1/apps/
+        cp icons/$1x32.png $out/share/icons/hicolor/$1/apps/zsnes.png
+    }
+    installIcon "16x16"
+    installIcon "32x32"
+    installIcon "48x48"
+    installIcon "64x64"
+
+    mkdir -p $out/share/applications
+    ln -s ${desktopItem}/share/applications/* $out/share/applications/
+  '';
+
+  meta = {
+    description = "A Super Nintendo Entertainment System Emulator";
+    license = stdenv.lib.licenses.gpl2Plus;
+    maintainers = [ stdenv.lib.maintainers.sander ];
+    homepage = http://www.zsnes.com;
+    platforms = [ "i686-linux" "x86_64-linux" ];
+  };
+}