1

I'm using NixOS and trying to learn SDL, yesterday I got a code example to build and work but today it stopped working, I tried rebuilding everything in a different directory with no success. I'm using a shell.nix to create the environment. I'm using dwm and on X11 The exact error I'm getting is Couldn't create window and renderer: No available video device

I have already checked that the DISPLAY env variable is set to 0 and inline setting it to 1 and 0

shell.nix:

{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell
{
 buildInputs = with pkgs; [
 sdl3
 pkg-config
 #SDL2.dev
 clang
 cmake
 ];
 packages = with pkgs;
 [
 alsa-lib
 jack2
 egl-wayland
 sdl3
 cmake
 pkg-config
 xorg.libX11
 xorg.libXext
 xorg.libXcursor
 xorg.libXi
 xorg.libXfixes
 xorg.libXrandr
 libpulseaudio
 #udev
 wayland
 libxkbcommon
 ];
 #LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath [pkgs.libpulseaudio pkgs.udev pkgs.xorg.libX11 pkgs.xorg.libXext pkgs.wayland pkgs.libxkbcommon]}";
 #LD_PRELOAD = "${pkgs.vulkan-loader.outPath}/lib/libvulkan.so";
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(hello)
# set the output directory for built objects.
# This makes sure that the dynamic library goes into the build directory automatically.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
# This assumes the SDL source is available in vendored/SDL
add_subdirectory(vendored/SDL EXCLUDE_FROM_ALL)
# Create your game executable target as usual
add_executable(hello WIN32 hello.c)
# Link to the actual SDL3 library.
target_link_libraries(hello PRIVATE SDL3::SDL3)

hello.c

/*
 Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
 This software is provided 'as-is', without any express or implied
 warranty. In no event will the authors be held liable for any damages
 arising from the use of this software.
 Permission is granted to anyone to use this software for any purpose,
 including commercial applications, and to alter it and redistribute it
 freely.
*/
#define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
static SDL_Window *window = NULL;
static SDL_Renderer *renderer = NULL;
/* This function runs once at startup. */
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
{
 /* Create the window */
 if (!SDL_CreateWindowAndRenderer("Hello World", 800, 600, SDL_WINDOW_FULLSCREEN, &window, &renderer)) {
 SDL_Log("Couldn't create window and renderer: %s", SDL_GetError());
 return SDL_APP_FAILURE;
 }
 return SDL_APP_CONTINUE;
}
/* This function runs when a new event (mouse input, keypresses, etc) occurs. */
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
 if (event->type == SDL_EVENT_KEY_DOWN ||
 event->type == SDL_EVENT_QUIT) {
 return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */
 }
 return SDL_APP_CONTINUE;
}
/* This function runs once per frame, and is the heart of the program. */
SDL_AppResult SDL_AppIterate(void *appstate)
{
 const char *message = "Hello World!";
 int w = 0, h = 0;
 float x, y;
 const float scale = 4.0f;
 /* Center the message and scale it up */
 SDL_GetRenderOutputSize(renderer, &w, &h);
 SDL_SetRenderScale(renderer, scale, scale);
 x = ((w / scale) - SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE * SDL_strlen(message)) / 2;
 y = ((h / scale) - SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE) / 2;
 /* Draw the message */
 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
 SDL_RenderClear(renderer);
 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
 SDL_RenderDebugText(renderer, x, y, message);
 SDL_RenderPresent(renderer);
 return SDL_APP_CONTINUE;
}
/* This function runs once at shutdown. */
void SDL_AppQuit(void *appstate, SDL_AppResult result)
{
}

I followed the tutorial on using CMake from the official sdl github repo

asked Jun 25, 2025 at 2:06
3
  • In the "related questions" section there is a link that is similar to your problem. Did it help? Commented Jun 25, 2025 at 20:12
  • @CraigEstey unfortunately it did not, there are plenty of posts about this error but most of them are related to the libraries on their system, which are different from nix. Maybe if I was more familiarized with the difference I'd be able to tell what the equivalent is. However after experimenting a bit more I found that SDL can't link to x11 Commented Jun 25, 2025 at 22:21
  • Don't you need to call SDL_Init as the first thing in SDL_AppInit? The examples I've seen posted seem to all do it. And, why do you think that SDL can't link to x11? I'd be more inclined to think that you built it without the proper x11 plugin/driver under SDL. Or, x11 isn't installed correctly relative to where SDL expects it. On my system, AFAICT, libSDL* uses libdl to dynamically load the backend. So, maybe running your app under strace will help. What happens if you bypass nix and try to build things manually? Commented Jun 26, 2025 at 17:49

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.