mio-ops/profiles/qemu.nix

57 lines
2.1 KiB
Nix
Raw Permalink 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
2022-03-07 14:26:15 +00:00
{
config,
pkgs,
lib,
...
}:
with lib; let
2020-12-31 02:19:52 +00:00
cfg = config.qemu-user;
arm = {
interpreter = "${pkgs.qemu-user-arm}/bin/qemu-arm";
2022-03-07 14:26:15 +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";
2022-03-07 14:26:15 +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";
2022-03-07 14:26:15 +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";
2022-03-07 14:26:15 +00:00
default = [];
2020-12-31 02:19:52 +00:00
};
};
config = mkIf (cfg.arm || cfg.aarch64) {
2022-03-07 14:26:15 +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;};
2021-11-16 04:57:23 +00:00
nix.supportedPlatforms =
2022-03-07 14:26:15 +00:00
(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
'';
2022-03-07 14:26:15 +00:00
nix.sandboxPaths =
["/run/binfmt"]
2021-11-16 04:57:23 +00:00
++ (optional cfg.arm "${pkgs.qemu-user-arm}")
++ (optional cfg.aarch64 "${pkgs.qemu-user-arm64}");
2020-12-31 02:19:52 +00:00
};
}