2022-06-16 17:23:12 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchFromGitHub
|
2022-12-17 10:02:37 +00:00
|
|
|
, gitUpdater
|
2022-06-16 17:23:12 +00:00
|
|
|
, cmake
|
|
|
|
, python3
|
2023-11-16 04:20:00 +00:00
|
|
|
, withDynarec ? (stdenv.hostPlatform.isAarch64 || stdenv.hostPlatform.isRiscV64)
|
2023-02-02 18:25:31 +00:00
|
|
|
, runCommand
|
|
|
|
, hello-x86_64
|
2022-06-16 17:23:12 +00:00
|
|
|
}:
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
# Currently only supported on ARM & RISC-V
|
|
|
|
assert withDynarec -> (stdenv.hostPlatform.isAarch64 || stdenv.hostPlatform.isRiscV64);
|
2023-02-02 18:25:31 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
2022-06-16 17:23:12 +00:00
|
|
|
pname = "box64";
|
2024-01-25 14:12:00 +00:00
|
|
|
version = "0.2.6";
|
2022-06-16 17:23:12 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "ptitSeb";
|
2023-11-16 04:20:00 +00:00
|
|
|
repo = "box64";
|
|
|
|
rev = "v${finalAttrs.version}";
|
2024-01-25 14:12:00 +00:00
|
|
|
hash = "sha256-eKYnBuaEWRb6kDGFvuG+xM70LbUAcJ6Zcr6hPHqi9Do=";
|
2022-06-16 17:23:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
cmake
|
|
|
|
python3
|
|
|
|
];
|
|
|
|
|
|
|
|
cmakeFlags = [
|
2023-02-02 18:25:31 +00:00
|
|
|
"-DNOGIT=ON"
|
2023-11-16 04:20:00 +00:00
|
|
|
|
|
|
|
# Arch mega-option
|
|
|
|
"-DARM64=${lib.boolToString stdenv.hostPlatform.isAarch64}"
|
|
|
|
"-DRV64=${lib.boolToString stdenv.hostPlatform.isRiscV64}"
|
|
|
|
"-DPPC64LE=${lib.boolToString (stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian)}"
|
|
|
|
"-DLARCH64=${lib.boolToString stdenv.hostPlatform.isLoongArch64}"
|
2023-02-02 18:25:31 +00:00
|
|
|
] ++ lib.optionals stdenv.hostPlatform.isx86_64 [
|
2023-11-16 04:20:00 +00:00
|
|
|
# x86_64 has no arch-specific mega-option, manually enable the options that apply to it
|
2023-02-02 18:25:31 +00:00
|
|
|
"-DLD80BITS=ON"
|
|
|
|
"-DNOALIGN=ON"
|
2023-11-16 04:20:00 +00:00
|
|
|
] ++ [
|
|
|
|
# Arch dynarec
|
|
|
|
"-DARM_DYNAREC=${lib.boolToString (withDynarec && stdenv.hostPlatform.isAarch64)}"
|
|
|
|
"-DRV64_DYNAREC=${lib.boolToString (withDynarec && stdenv.hostPlatform.isRiscV64)}"
|
2023-02-02 18:25:31 +00:00
|
|
|
];
|
2022-06-16 17:23:12 +00:00
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
2023-02-02 18:25:31 +00:00
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
install -Dm 0755 box64 "$out/bin/box64"
|
2023-02-02 18:25:31 +00:00
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
|
2022-06-16 17:23:12 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
doInstallCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
|
2022-06-16 17:23:12 +00:00
|
|
|
|
|
|
|
installCheckPhase = ''
|
|
|
|
runHook preInstallCheck
|
2023-02-02 18:25:31 +00:00
|
|
|
|
|
|
|
echo Checking if it works
|
2022-06-16 17:23:12 +00:00
|
|
|
$out/bin/box64 -v
|
2023-02-02 18:25:31 +00:00
|
|
|
|
|
|
|
echo Checking if Dynarec option was respected
|
|
|
|
$out/bin/box64 -v | grep ${lib.optionalString (!withDynarec) "-v"} Dynarec
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
runHook postInstallCheck
|
|
|
|
'';
|
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
passthru = {
|
|
|
|
updateScript = gitUpdater {
|
|
|
|
rev-prefix = "v";
|
|
|
|
};
|
|
|
|
tests.hello = runCommand "box64-test-hello" {
|
2023-11-16 04:20:00 +00:00
|
|
|
nativeBuildInputs = [ finalAttrs.finalPackage ];
|
2023-02-02 18:25:31 +00:00
|
|
|
} ''
|
|
|
|
# There is no actual "Hello, world!" with any of the logging enabled, and with all logging disabled it's hard to
|
|
|
|
# tell what problems the emulator has run into.
|
|
|
|
BOX64_NOBANNER=0 BOX64_LOG=1 box64 ${hello-x86_64}/bin/hello --version | tee $out
|
|
|
|
'';
|
2022-12-17 10:02:37 +00:00
|
|
|
};
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
meta = with lib; {
|
|
|
|
homepage = "https://box86.org/";
|
|
|
|
description = "Lets you run x86_64 Linux programs on non-x86_64 Linux systems";
|
|
|
|
license = licenses.mit;
|
2023-02-02 18:25:31 +00:00
|
|
|
maintainers = with maintainers; [ gador OPNA2608 ];
|
2023-11-16 04:20:00 +00:00
|
|
|
mainProgram = "box64";
|
|
|
|
platforms = [ "x86_64-linux" "aarch64-linux" "riscv64-linux" "powerpc64le-linux" "loongarch64-linux" "mips64el-linux" ];
|
2022-06-16 17:23:12 +00:00
|
|
|
};
|
2023-11-16 04:20:00 +00:00
|
|
|
})
|