mio-ops/profiles/qemu.nix

59 lines
2.2 KiB
Nix
Raw Normal View History

2020-12-31 02:19:52 +00:00
# Based up original work by cleverca22
# https://github.com/cleverca22/nixos-configs/blob/master/qemu.nix
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.qemu-user;
arm = {
interpreter = "${pkgs.qemu-user-arm}/bin/qemu-arm";
2021-11-16 04:57:23 +00:00
magicOrExtension =
"\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28\\x00";
mask =
"\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xfe\\xff\\xff\\xff";
2020-12-31 02:19:52 +00:00
};
aarch64 = {
interpreter = "${pkgs.qemu-user-arm64}/bin/qemu-aarch64";
2021-11-16 04:57:23 +00:00
magicOrExtension =
"\\x7fELF\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\xb7\\x00";
mask =
"\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xfe\\xff\\xff\\xff";
2020-12-31 02:19:52 +00:00
};
riscv64 = {
interpreter = "${pkgs.qemu-riscv64}/bin/qemu-riscv64";
2021-11-16 04:57:23 +00:00
magicOrExtension =
"\\x7fELF\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\xf3\\x00";
mask =
"\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xfe\\xff\\xff\\xff";
2020-12-31 02:19:52 +00:00
};
in {
options = {
qemu-user = {
arm = mkEnableOption "enable 32bit arm emulation";
aarch64 = mkEnableOption "enable 64bit arm emulation";
riscv64 = mkEnableOption "enable 64bit riscv emulation";
};
nix.supportedPlatforms = mkOption {
type = types.listOf types.str;
description = "extra platforms that nix will run binaries for";
2021-11-16 04:57:23 +00:00
default = [ ];
2020-12-31 02:19:52 +00:00
};
};
config = mkIf (cfg.arm || cfg.aarch64) {
2021-11-16 04:57:23 +00:00
nixpkgs = { overlays = [ (import ../overlays/qemu) ]; };
boot.binfmt.registrations = optionalAttrs cfg.arm { inherit arm; }
// optionalAttrs cfg.aarch64 { inherit aarch64; }
// optionalAttrs cfg.riscv64 { inherit riscv64; };
nix.supportedPlatforms =
(optionals cfg.arm [ "armv6l-linux" "armv7l-linux" ])
2020-12-31 02:19:52 +00:00
++ (optional cfg.aarch64 "aarch64-linux");
nix.extraOptions = ''
extra-platforms = ${toString config.nix.supportedPlatforms} i686-linux
'';
2021-11-16 04:57:23 +00:00
nix.sandboxPaths = [ "/run/binfmt" ]
++ (optional cfg.arm "${pkgs.qemu-user-arm}")
++ (optional cfg.aarch64 "${pkgs.qemu-user-arm64}");
2020-12-31 02:19:52 +00:00
};
}