tpwrules / nixos-apple-silicon

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

mesa 23.0.1 blocks loading of drivers built with different version #67

Closed yu-re-ka closed 8 months ago

yu-re-ka commented 1 year ago
  hardware.asahi.experimentalGPUInstallMode = "driver";
  hardware.asahi.useExperimentalGPUDriver = true;
  hardware.asahi.addEdgeKernelConfig = true;
00:00:00.009 [ERROR] [wlr] [EGL] command: eglQueryDeviceStringEXT, error: EGL_BAD_PARAMETER (0x300c), message: "eglQueryDeviceStringEXT"
00:00:00.009 [ERROR] [wlr] [EGL] command: eglQueryDeviceStringEXT, error: EGL_BAD_PARAMETER (0x300c), message: "eglQueryDeviceStringEXT"
DRI driver not from this Mesa build ('23.1.0-devel' vs '23.0.1')
failed to bind extensions
MESA-LOADER: failed to open zink: /run/opengl-driver/lib/dri/zink_dri.so: cannot open shared object file: No such file or directory (search paths /run/opengl-driver/lib
/dri, suffix _dri)
DRI driver not from this Mesa build ('23.1.0-devel' vs '23.0.1')
failed to bind extensions
DRI driver not from this Mesa build ('23.1.0-devel' vs '23.0.1')
failed to bind extensions
00:00:00.020 [ERROR] [wlr] [render/egl.c:538] Failed to create GBM device
00:00:00.020 [ERROR] [wlr] [render/egl.c:554] Failed to initialize EGL context
00:00:00.020 [ERROR] [wlr] [render/gles2/renderer.c:679] Could not initialize EGL

In this case we should probably package multiple versions that are rebased on top of the corresponding mesa version

idm1try commented 1 year ago

i have same error, any way to fix it?

yu-re-ka commented 1 year ago

I ended up switching to hardware.asahi.experimentalGPUInstallMode = "replace";

QuentinI commented 1 year ago

any way to fix it?

Lie and cheat! Extremely cursed, but if you don't want to rebuild the world nor give up pure builds, it's an option.

tpwrules commented 1 year ago

I am very wary of that solution. It probably invites substantial nasal demons. I can only assume there's a reason the Mesa folks have added that check. I also do not think it is feasible for me to maintain multiple patchsets for different Mesa versions.

It's worth noting that builds are always pure, even with --impure or when not using flakes. It's just the evaluation which is impure, which is unlikely to cause problems assuming pure evaluation works in the other graphics driver modes, which I regularly test.

A better long-term solution would be to fix system.replaceRuntimeDependencies to work in pure evaluation mode. I'm not sure of the status of upstream work on that.

QuentinI commented 1 year ago

I am very wary of that solution. It probably invites substantial nasal demons. I can only assume there's a reason the Mesa folks have added that check.

Of course, that's why I didn't make a PR with that. It's just a hack I employed for myself to get eaten by Zalgo.

It's worth noting that builds are always pure, even with --impure or when not using flakes. It's just the evaluation which is impure, which is unlikely to cause problems assuming pure evaluation works in the other graphics driver modes, which I regularly test.

I meant evaluation of course, sorry for my parlance.

A better long-term solution would be to fix system.replaceRuntimeDependencies to work in pure evaluation mode. I'm not sure of the status of upstream work on that.

Doesn't that just move the possible nasal demons from mesa/driver interface to mesa/application interface?

tpwrules commented 1 year ago

Doesn't that just move the possible nasal demons from mesa/driver interface to mesa/application interface?

No, the mesa/application interface is defined and has stability guarantees. Consider that the official Asahi Linux distro doesn't rebuild everything in the Arch repositories with their Mesa. They just drop the new Mesa libraries on disk and go. Compare splitting Mesa itself in half, which Mesa now specifically checks for and rejects. Forcing the second is much, much shakier.

ingenieroariel commented 1 year ago

I see apple_dri.so and asahi_dri.so on /run/opengl-driver/lib/dri but get the same zink_dri.so error and software rendering when I start sway.

In my case I did the overlay and rebuilt the world, so the driver is there and the default mesa.

flake.nix

{
  description = "A very basic flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/master";
    firefox = {
      url = github:colemickens/flake-firefox-nightly;
      inputs.nixpkgs.follows = "nixpkgs";
    };
    home-manager = {
      url = github:nix-community/home-manager;
      inputs.nixpkgs.follows = "nixpkgs";
    };
    rust-overlay = {
      url = github:oxalica/rust-overlay;
      inputs.nixpkgs.follows = "nixpkgs";
    };

    nixos-m1-overlay = {
      url = github:tpwrules/nixos-apple-silicon;
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.rust-overlay.follows = "rust-overlay";
    };
  };

  outputs = {
    self,
    nixpkgs,
    rust-overlay,
    nixos-m1-overlay,
    firefox,
    home-manager,
  }: let
    system = "aarch64-linux";

    pkgs = import nixpkgs {
      inherit system;
      config.allowUnfree = true;
      overlays = [ 
          rust-overlay.overlays.default
          nixos-m1-overlay.overlays.default
          (final: prev: {
             mesa = (pkgs.mesa-asahi-edge.override { 
              galliumDrivers = [ "swrast" "asahi" ];
             }).overrideAttrs (oldAttrs: {
                version = oldAttrs.version;
                postPath = oldAttrs.postPatch
                  +  ''
                      $(oldAttrs.psotPatch)
                      echo ${oldAttrs.version} >> VERSION
                  '';
             });
             firefox = prev.wrapFirefox prev.firefox {
              extraPrefs = ''
                  // Show more ssl cert infos
                   lockPref("security.identityblock.show_extended_validation", true);
                  '';
              extraPolicies = {
                CaptivePortal = false;
                DisableFirefoxStudies = true;
                DisablePocket = true;
                DisableTelemetry = true;
                DisableFirefoxAccounts = true;
                FirefoxHome = {
                  Pocket = false;
                  Snippets = false;
                };
                UserMessaging = {
                  ExtensionRecommendations = false;
                  SkipOnboarding = true;
                };
                SecurityDevices = {
                  # Use a proxy module rather than `nixpkgs.config.firefox.smartcardSupport = true`
                  "PKCS#11 Proxy Module" = "${pkgs.p11-kit}/lib/p11-kit-proxy.so";
                };
              };
            };
           })
      ];
    };
    lib = nixpkgs.lib;
  in {
    nixosConfigurations = {
      decpti = lib.nixosSystem {
        inherit system;
        modules = [
          ./configuration.nix
          nixos-m1-overlay.nixosModules.default
          home-manager.nixosModules.home-manager
          {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
          }
        ];
         };
    };
  };
}

configuration.nix

{ config, pkgs, lib, ... }:
{
  imports =
  [ ./hardware-configuration.nix
  ];

  boot.kernelPatches = [
      {
        name = "edge-config";
        patch = null;
        # derived from
        # https://github.com/AsahiLinux/PKGBUILDs/blob/stable/linux-asahi/config.edge
        extraConfig = ''
          DRM_SIMPLEDRM_BACKLIGHT n
          BACKLIGHT_GPIO n
          DRM_APPLE m
          APPLE_SMC m
          APPLE_SMC_RTKIT m
          APPLE_RTKIT m
          APPLE_MBOX m
          GPIO_MACSMC m
          DRM_VGEM n
          DRM_SCHED y
          DRM_GEM_SHMEM_HELPER y
          DRM_ASAHI m
          SUSPEND y
        '';
      }
    ];
  services.xserver.config = ''
    Section "OutpuClass"
      Identifier "appledrm"
      MatchDriver "apple"
      Driver "modesetting"
      Option "PrimaryGPU" "true"
    EndSection
  '';
  hardware.opengl.package = pkgs.mesa-asahi-edge.drivers;
  nixpkgs.overlays = [
    (final: prev: {
      mesa = final.mesa-asahi-edge;
    })
  ];
  hardware.asahi.experimentalGPUInstallMode = "replace";
  hardware.opengl.enable = true;
  hardware.asahi.withRust = true;
  hardware.asahi.addEdgeKernelConfig = true;

  nixpkgs.config.allowUnfree = true;

  programs.xwayland.enable = false;
  programs.sway = {
    enable = true;
    wrapperFeatures.gtk = false;
  };

  hardware.asahi.extractPeripheralFirmware = false;
  boot.loader.systemd-boot.enable = true;
  # U-boot does not supprot EFI variables
  boot.loader.efi.canTouchEfiVariables = false;
  system.stateVersion = lib.mkDefault lib.trivial.release;
}
ingenieroariel commented 1 year ago

After a nix flake update the config above worked, turns out it was not picking up the latest changes in the repo. I'll try to remove the duplicated config now that everything is rebuilt and working fast.

pupbrained commented 10 months ago

I've tried the fixes mentioned but none of them seem to work. Spoofing the mesa version temporarily works, but after a reboot I'm stuck on software rendering. I tried using replace instead of overlay for the GPU install method but both seem to do the same thing:

DRI driver not from this Mesa build ('23.3.0-devel' vs '23.1.5')

mitsuruu commented 8 months ago

I'm getting the same thing as well with my configuration. I've tried everything listed here, as well as even using someone else's Flake which worked on their NixOS Asahi Linux laptop, however I'm unable to start a Hyprland desktop session because of this bug. Hopefully something will come of this issue soon, as I'm unable to replicate this issue on Arch Asahi Linux.

yu-re-ka commented 8 months ago

I'm happily using hardware.asahi.experimentalGPUInstallMode = "replace";