builders: Enable user mode emulation for RISC-V and ARM

This commit is contained in:
Mikael 2024-11-29 16:41:23 +01:00
parent 8a93fb6c56
commit d0e97fa1ed
Signed by: mikael
SSH key fingerprint: SHA256:21QyD2Meiot7jOUVitIR5YkGB/XuXdCvLW1hE6dsri0
3 changed files with 19 additions and 2 deletions

View file

@ -6,6 +6,7 @@
bash,
gnused,
util-linux,
qemu-user
}:
dockerTools.buildLayeredImage {
@ -20,7 +21,7 @@ dockerTools.buildLayeredImage {
enableFakechroot = true;
contents = [ openssh util-linux bash gnused ];
contents = [ openssh util-linux bash gnused qemu-user ];
config.Cmd = [ "/entrypoint.sh" ];

View file

@ -26,4 +26,16 @@ cp /root/nix.conf /etc/nix/nix.conf
/bin/mount -t overlay overlay -o lowerdir=/nix,upperdir=/mnt/data/nix-store,workdir=/mnt/data/workdir /nix
/bin/mount --bind /mnt/data/tmp /tmp
# Register QEMU binaries for user mode emulation
aarch64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00'
aarch64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
riscv64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00'
riscv64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
execPath() { readlink -f "$(which "$1")" }
echo ":qemu-aarch64:M::$aarch64_magic:$aarch64_mask:$(execPath qemu-aarch64):POCF" >/proc/sys/fs/binfmt_misc/register
echo ":qemu-riscv64:M::$riscv64_magic:$riscv64_mask:$(execPath qemu-riscv64):POCF" >/proc/sys/fs/binfmt_misc/register
/root/.nix-profile/bin/sshd -D -f /root/sshd_config

View file

@ -2,7 +2,11 @@ final: prev: {
nyastodon = final.callPackage ./nyastodon/default.nix {};
upgrade-system = final.callPackage ./upgrade-system/default.nix {};
update-nixfiles = final.callPackage ./update-nixfiles/default.nix {};
build-worker-oci = final.callPackage ./build-worker-oci/default.nix {};
build-worker-oci = final.callPackage ./build-worker-oci/default.nix {
qemu-user = final.pkgsStatic.qemu-user.override {
hostCpuTargets = [ "aarch64-linux-user" "riscv64-linux-user" ];
};
};
librespeed-rust = final.callPackage ./librespeed-rust/default.nix {};
librespeed-go = final.callPackage ./librespeed-go/default.nix {};
akkoma-fe-domi = final.callPackage ./akkoma-fe-domi/default.nix {};