/
qemu.nix
42 lines (41 loc) · 1.59 KB
/
qemu.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.qemu-user;
arm = {
interpreter = "${pkgs.qemu-user-arm}/bin/qemu-arm";
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'';
};
aarch64 = {
interpreter = "${pkgs.qemu-user-arm64}/bin/qemu-aarch64";
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'';
};
in {
options = {
qemu-user = {
arm = mkEnableOption "enable 32bit arm emulation";
aarch64 = mkEnableOption "enable 64bit arm emulation";
};
nix.supportedPlatforms = mkOption {
type = types.listOf types.str;
description = "extra platforms that nix will run binaries for";
default = [];
};
};
config = mkIf (cfg.arm || cfg.aarch64) {
nixpkgs = {
overlays = [ (import ./overlays/qemu-user.nix) ];
};
boot.binfmtMiscRegistrations =
optionalAttrs cfg.arm { inherit arm; } //
optionalAttrs cfg.aarch64 { inherit aarch64; };
nix.supportedPlatforms = (optionals cfg.arm [ "armv6l-linux" "armv7l-linux" ]) ++ (optional cfg.aarch64 "aarch64-linux");
nix.package = pkgs.patchedNix;
nix.extraOptions = ''
build-extra-platforms = ${toString config.nix.supportedPlatforms}
'';
nix.sandboxPaths = [ "/run/binfmt" ] ++ (optional cfg.arm "${pkgs.qemu-user-arm}") ++ (optional cfg.aarch64 "${pkgs.qemu-user-arm64}");
};
}