diff options
author | Matthew Bauer <mjbauer95@gmail.com> | 2018-11-29 19:34:20 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-29 19:34:20 -0600 |
commit | f435272ce351ed192e9ff9c643331a4cc063930e (patch) | |
tree | 09d2cd01d0062578f61c4712fb73ab6b29313b45 /lib/systems | |
parent | 1cd300e57b35b5e075a56ba9bea348f209620191 (diff) | |
parent | 9c8fd412248ad907eee7547b19bf3f7583d2c411 (diff) |
Merge pull request #50212 from matthewbauer/host-emulator
Add "emulator" function to systems
Diffstat (limited to 'lib/systems')
-rw-r--r-- | lib/systems/default.nix | 40 | ||||
-rw-r--r-- | lib/systems/examples.nix | 13 |
2 files changed, 48 insertions, 5 deletions
diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 0b3475fefb9ce..25df5e1740697 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -66,6 +66,46 @@ rec { # uname -r release = null; }; + + qemuArch = + if final.isArm then "arm" + else if final.isx86_64 then "x86_64" + else if final.isx86 then "i386" + else { + "powerpc" = "ppc"; + "powerpc64" = "ppc64"; + "powerpc64le" = "ppc64"; + "mips64" = "mips"; + "mipsel64" = "mipsel"; + }.${final.parsed.cpu.name} or final.parsed.cpu.name; + + emulator = pkgs: let + qemu-user = pkgs.qemu.override { + smartcardSupport = false; + spiceSupport = false; + openGLSupport = false; + virglSupport = false; + vncSupport = false; + gtkSupport = false; + sdlSupport = false; + pulseSupport = false; + smbdSupport = false; + seccompSupport = false; + hostCpuTargets = ["${final.qemuArch}-linux-user"]; + }; + wine-name = "wine${toString final.parsed.cpu.bits}"; + wine = (pkgs.winePackagesFor wine-name).minimal; + in + if final.parsed.kernel.name == pkgs.stdenv.hostPlatform.parsed.kernel.name && + (final.parsed.cpu.name == pkgs.stdenv.hostPlatform.parsed.cpu.name || + (final.platform.isi686 && pkgs.stdenv.hostPlatform.isx86_64)) + then pkgs.runtimeShell + else if final.isWindows + then "${wine}/bin/${wine-name}" + else if final.isLinux && pkgs.stdenv.hostPlatform.isLinux + then "${qemu-user}/bin/qemu-${final.qemuArch}" + else throw "Don't know how to run ${final.config} executables."; + } // mapAttrs (n: v: v final.parsed) inspect.predicates // args; in assert final.useAndroidPrebuilt -> final.isAndroid; diff --git a/lib/systems/examples.nix b/lib/systems/examples.nix index acd673df666fb..c799b9ec4496c 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -2,7 +2,14 @@ # `crossSystem`. They are put here for user convenience, but also used by cross # tests and linux cross stdenv building, so handle with care! { lib }: -let platforms = import ./platforms.nix { inherit lib; }; in +let + platforms = import ./platforms.nix { inherit lib; }; + + riscv = bits: { + config = "riscv${bits}-unknown-linux-gnu"; + platform = platforms.riscv-multiplatform bits; + }; +in rec { # @@ -92,10 +99,6 @@ rec { musl64 = { config = "x86_64-unknown-linux-musl"; }; musl32 = { config = "i686-unknown-linux-musl"; }; - riscv = bits: { - config = "riscv${bits}-unknown-linux-gnu"; - platform = platforms.riscv-multiplatform bits; - }; riscv64 = riscv "64"; riscv32 = riscv "32"; |