# GLFW not showing window under Wayland or X11 on NixOS

**URL:** https://discourse.glfw.org/t/glfw-not-showing-window-under-wayland-or-x11-on-nixos/2371
**Category:** support
**Created:** [May 3, 2023, 3:22am UTC](https://discourse.glfw.org/t/glfw-not-showing-window-under-wayland-or-x11-on-nixos/2371 "2023-05-03T03:22:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rollschild](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/rollschild/32/763_2.png) [@rollschild](https://discourse.glfw.org/u/rollschild)
#### Post date: [May 3, 2023, 3:22am UTC](https://discourse.glfw.org/t/glfw-not-showing-window-under-wayland-or-x11-on-nixos/2371/1 "2023-05-03T03:22:03Z")

</div>

Hi Community,

This is my first time posting here. I’ve just starting learning GLFW via this [tutorial](https://eliemichel.github.io/LearnWebGPU/index.html). However, after initially setting up a very basic project the window would not show up at all under Wayland. I’m using a flake-based project on NixOS.

Relevant part of my `flake.nix` - this basically pulls in all the build dependencies:

```auto
          nativeBuildInputs = with pkgs; [
            # Development Tools
            llvm.lldb
            cmake
            cmakeCurses
            boost
            glfw-wayland

            clang-tools
            llvm.clang
          ];

```

My root level `CMakeLists.txt` which mentions glfw:

```auto
set(GLFW_USE_WAYLAND ON)
find_package(glfw3 REQUIRED)

```

My src level `CMakeLists.txt`:

```auto
find_package(glfw3 REQUIRED)
add_executable(App)
target_sources(App PRIVATE main.cpp)
target_link_libraries(App glfw)

```

My `main.cpp`:

```auto
#include <GLFW/glfw3.h>
#include <iostream>

int main() {
  // Any call to GLFW must happen between its initialization and termination
  if (!glfwInit()) {
    std::cerr << "Could NOT initialize GLFW!" << std::endl;
    return 1;
  }

  GLFWwindow *window = glfwCreateWindow(640, 480, "WebGPU for C++", NULL, NULL);
  if (!window) {
    std::cerr << "Could NOT open window!" << std::endl;
    glfwTerminate();
    return 1;
  }
  std::cout << "window:" << window << std::endl;

  glfwMakeContextCurrent(window);

  while (!glfwWindowShouldClose(window)) {
    glfwPollEvents();
  }

  glfwTerminate();
}

```

The project built successfully but when I ran the executable it just got stuck there forever (because of the `while` loop) and no window showed up at all. It printed the `window` pointer so I assume it at least successfully initialized.

After having no luck under Wayland, I switched to X11 desktop, changed the `glfw-wayland` in `flake.nix` to the statndard `glfw`, and removed the `set(GLFW_USE_WAYLAND ON)` flag. But this time the execution actually errored out with `Could NOT open window!` - it did not even initialize properly. So it’s not working for me under X11 either.

Where did I do wrong? Am I missing anything? Please help, thank you so much!

EDIT:  
The tutorial I mentioned at the beginning of this post doesn’t use any other libraries. But I did see some other places using `OpenGL` and even having `find_package(OpenGL REQUIRED)` in `CMakeLists.txt`. Do I need to do that?

---

<div class="post-metadata">

### Author: ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)
#### Post date: [May 3, 2023, 12:33pm UTC](https://discourse.glfw.org/t/glfw-not-showing-window-under-wayland-or-x11-on-nixos/2371/2 "2023-05-03T12:33:18Z")

</div>

Have you tried running the GLFW examples or tests? I would recommend doing that as a first step.

You can also try using:

> **[GitHub - juliettef/GLFW-CMake-starter: Use CMake to create a project with GLFW...](https://github.com/juliettef/GLFW-CMake-starter)**
>
> Use CMake to create a project with GLFW - Multi-platform Windows, Linux and MacOS. - GitHub - juliettef/GLFW-CMake-starter: Use CMake to create a project with GLFW - Multi-platform Windows, Linux a...

OpenGL is only required if you want to use OpenGL (easiest option for graphics), otherwise you can use Vulkan (harder option for graphics as very low level). If you’re calling `glfwMakeContextCurrent` this is for OpenGL.

---

<div class="post-metadata">

### Author: ![elmindreda](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/elmindreda/32/26_2.png) [@elmindreda](https://discourse.glfw.org/u/elmindreda)
#### Post date: [May 31, 2023, 8:47pm UTC](https://discourse.glfw.org/t/glfw-not-showing-window-under-wayland-or-x11-on-nixos/2371/3 "2023-05-31T20:47:48Z")

</div>

On Wayland specifically, you need to swap the buffers of a window for it to become visible.

---

<div class="post-metadata">

### Author: ![pamo22](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@pamo22](https://discourse.glfw.org/u/pamo22)
#### Post date: [February 22, 2024, 5:42am UTC](https://discourse.glfw.org/t/glfw-not-showing-window-under-wayland-or-x11-on-nixos/2371/4 "2024-02-22T05:42:01Z")

</div>

This was my issue, thanks.
