tpwrules / nixos-apple-silicon

Resources to install NixOS bare metal on Apple Silicon Macs
MIT License
872 stars 88 forks source link

Integrating Fex support #237

Open rowanG077 opened 1 month ago

rowanG077 commented 1 month ago

With fex + vulkan seeming to be pretty close on fedora asahi I think we should start thinking about how we can support fex on nixos. As far as I see it a few different things need to happen for that:

I personally have little experience how rootfs + krun functions so this is more to get the discussion started. I'm willing to work on this so if anyone has any pointers to achieve this that would help as well.

rowanG077 commented 1 month ago

Pinging @RossComputerGuy as you have packaged krun aka muvm upstream. Currently it crashes for me but maybe that is known.

RossComputerGuy commented 4 weeks ago

This is definitely a good idea and I can look into it when I have a moment. (I should rename krun to muvm in nixpkgs, didn't know about the rename until recently)

rowanG077 commented 4 weeks ago

This is a fex derivation, I can't test it because you need a 4K pagesize system to run it. For which we will need muvm. If you disable tests though it fully builds and you can at the very least run FEXConfig.

{ lib, stdenv, clangStdenv, fetchgit, cmake, clang, ninja, pkg-config, lld, llvm
, llvmPackages, openssl, glibc, autoPatchelfHook, nasm, qt5, python, setuptools
, libclang
}:

clangStdenv.mkDerivation rec {
  pname = "fex-emu";
  version = "2410";

  src = fetchgit {
    url = "https://github.com/FEX-Emu/FEX.git";
    rev = "FEX-${version}";
    sha256 = "sha256-btzb7OGa3M89wDn8AK/iocT3GLY1mB3cZ0iuWAyNIFc=";
    fetchSubmodules = true;
  };

  nativeBuildInputs = [
    cmake
    clang
    ninja
    pkg-config
    nasm
    qt5.wrapQtAppsHook
    # required with "-DUSE_LINKER=lld"
    # lld
    # autoPatchelfHook
  ];

  buildInputs = [
    llvm
    python
    setuptools
    libclang
    openssl.dev
    qt5.full
  ];

  cmakeFlags = [
    # upstream recommends this but binaries have linker issues
    # libstdc++.so.6: cannot open shared object file: No such file or directory
    # autoPatchelfHook fixes that for the output binaries but test are run
    # by cmake prior to that
    # "-DUSE_LINKER=lld"
    "-DENABLE_ASSERTIONS=FALSE"
    "-DBUILD_TESTS=FALSE"
    "-DOVERRIDE_VERSION=FEX-${version}"
  ];

  meta = with lib; {
    description = "FEX - Fast x86 emulation frontend";
    homepage = "https://github.com/FEX-Emu/FEX";
    license = licenses.mit;
    platforms = platforms.linux;
    maintainers = with maintainers; [ rowanG077 ];
  };
}
Lemm1 commented 3 weeks ago

This is a fex derivation, I can't test it because you need a 4K pagesize system to run it. For which we will need muvm. If you disable tests though it fully builds and you can at the very least run FEXConfig.

The problem with FEX is to create RootFS, there are prebuilds for fedora, arch and ubuntu. So for nixos you will need to create your own. I've tried to do it few months ago, but it wasn't that easy as creating FEX package. Also in order to make something distributable it will require some nix wizard to somehow either automate RootFS creation on package build or to have prebuilt RootFS distributed like FEX do it for some distros. I personally gave up on that and started using distrobox for FEX