about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorArtturin <Artturin@artturin.com>2022-09-06 21:43:33 +0300
committerArtturin <Artturin@artturin.com>2022-09-11 19:34:15 +0300
commit20f90d392141a155386ea2143048b4d755d07988 (patch)
tree7734c4199b7a902bdaf32257ab8bdc86662f374f /lib
parent750bb8057c0b813f076a97b9f9380ee430274257 (diff)
lib/systems: add emulatorAvailable
```
nix-repl> pkgsCross.arm-embedded.stdenv.hostPlatform.emulatorAvailable pkgsCross.arm-embedded.buildPackages
false

nix-repl> pkgsCross.aarch64-multiplatform.stdenv.hostPlatform.emulatorAvailable pkgsCross.aarch64-multiplatform.buildPackages
true
```

will be useful for stuff like handling https://github.com/NixOS/nixpkgs/issues/187109
Diffstat (limited to 'lib')
-rw-r--r--lib/systems/default.nix69
1 files changed, 39 insertions, 30 deletions
diff --git a/lib/systems/default.nix b/lib/systems/default.nix
index eaee4ffa2874d..518073863a3e8 100644
--- a/lib/systems/default.nix
+++ b/lib/systems/default.nix
@@ -158,38 +158,47 @@ rec {
         if final.isMacOS then "MACOSX_DEPLOYMENT_TARGET"
         else if final.isiOS then "IPHONEOS_DEPLOYMENT_TARGET"
         else null;
+    } // (
+      let
+        selectEmulator = 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 &&
+            pkgs.stdenv.hostPlatform.canExecute final
+          then "${pkgs.runtimeShell} -c '\"$@\"' --"
+          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 if final.isWasi
+          then "${pkgs.wasmtime}/bin/wasmtime"
+          else if final.isMmix
+          then "${pkgs.mmixware}/bin/mmix"
+          else null;
+      in {
+        emulatorAvailable = pkgs: (selectEmulator pkgs) != null;
 
-      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 &&
-           pkgs.stdenv.hostPlatform.canExecute final
-        then "${pkgs.runtimeShell} -c '\"$@\"' --"
-        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 if final.isWasi
-        then "${pkgs.wasmtime}/bin/wasmtime"
-        else if final.isMmix
-        then "${pkgs.mmixware}/bin/mmix"
-        else throw "Don't know how to run ${final.config} executables.";
+        emulator = pkgs:
+          if (final.emulatorAvailable pkgs)
+          then selectEmulator pkgs
+          else throw "Don't know how to run ${final.config} executables.";
 
-    } // mapAttrs (n: v: v final.parsed) inspect.predicates
+    }) // mapAttrs (n: v: v final.parsed) inspect.predicates
       // mapAttrs (n: v: v final.gcc.arch or "default") architectures.predicates
       // args;
   in assert final.useAndroidPrebuilt -> final.isAndroid;