Help with starting sway

I have tried searching everything related to sway/wayland/wlroots over the internet but couldn’t find anything that fixes my issue. Ir worked fine when I used Arch previously but after switching to NixOS, it just doesn’t start

Sway Error:-

LibEGL warning: Not allowed to force software rendering when API explicitly selects a hardware device.

LibEGL warning: MESA-LOADER: failed to open i915: /run/opengl-driver/lib/dri/ cannot open shared object file: No such file or directory (searches /run/opengl-driver/lib/dri, suffix dri)

00:00:00.292 [ulr] [EGL] command: eglInitialize, error: EGL_NOT_INITIALIZED (0x30013, nessage: "DRI2: failed to load driver"

00:00:00.292 [ulr] [EGL] command: eglInitialize, error: EGL_NOT_INITIALIZED (0x3001), message: "eglinitialize"

00:00:00.292 [ulr) [render/egl.c:2641 Failed to initialize EGL

00:00:00.292 [ulr] [render/egl.c:5541 Failed to initialize EGL context

00:00:00.292 [wlrl](render/gles2/renderer.c:6791 Could not initialize EGL

00:00:00.293 [wirl frender/ulr_renderer.c:3331 Could not initialize renderer

00:00:00.293 [sway/server.c:791 Failed to create renderer

I have set hardware.opengl.enable = true; in my configuration.nix.
I am using NixOS 23.05

It looks like DRI support might not be enabled?
I use Sway as well and have the following OpenGL options enabled:

hardware.opengl = {
enable = true;
driSupport = true;
driSupport32Bit = true;

Edit: Ah I didn’t realize driSupport defaults to true. So that might not actually help :confused:
Since you’re using intel, you might want to check that you have similar options compared to what’s in the nixos-hardware module for intel. nixos-hardware/common/gpu/intel/default.nix at 429f232fe1dc398c5afea19a51aad6931ee0fb89 · NixOS/nixos-hardware · GitHub

Thanks for that link but I don’t what should I do further with it. I am new to NixOS (Not to Nix btw) so please bear with me a little.

So I feel like from that we are really just trying to make sure that the “i915” module is loading.
boot.initrd.kernelModules = [ “i915” ];
Depending on how you installed NixOS this option might already be set in a hardware-configuration.nix near your configuration.nix file, if you have the option you can just add “i915” to it if it isn’t there already.

If you want the intel gpu options to just be added automatically you’re free to add the nixos-hardware channel following the readme (GitHub - NixOS/nixos-hardware: A collection of NixOS modules covering hardware quirks.), and add <nixos-hardware/common/gpu/intel> to your imports in configuration.nix. Using nixos-hardware isn’t required it’s just a convenience thing.

Hopefully that helps :slight_smile:

I added “i915” to my hardware-configuration.nix and it rebuild correctly but the error still persists.

EDIT: I also enabled driSupport and driSupport32Bit but the error remains the same.

I saw your error come up in a home-manager issue: sway does not start with EGL_NOT_INITIALIZED error · Issue #2150 · nix-community/home-manager · GitHub
Seems like it might be some sort of nixpkgs version mismatch, do you happen to be running the sway home-manager module?
This comment on the issue had one fix that worked for them if you are. Might be worth going through those threads.

If not I’m afraid I don’t really have any more ideas :confused:

I don’t have home-manager installed. It’s a freshly installed NixOS system.

Do you have hardware.opengl.enable set to true, like @Zen suggested? It’s not clear from your answers so far.

Thanks to @K900 solution over on Matrix, I was able to solve this issue. For future readers, you need to set the following in your configuration.nix (Override if it already exists) :-

hardware.opengl = {
  enable = true;
  package = (pkgs.mesa.override { galliumDrivers = [ "i915" ]; }).drivers

In case you encounter errors regarding saying the following:- ERROR: Problem Encountered: swrast vulkan requires galliun swrast

add "swrast" after "i915".

Also @K900 has opened up #239978 which should solve the issue in future releases.

1 Like

Great solution! Note that this will fail if you have only 4GB of memory without swap.