Skip to content

Instantly share code, notes, and snippets.

@monomadic
Last active December 6, 2022 18:43
Show Gist options
  • Save monomadic/d663c28f5f423d785ce8a67cba8b6ed7 to your computer and use it in GitHub Desktop.
Save monomadic/d663c28f5f423d785ce8a67cba8b6ed7 to your computer and use it in GitHub Desktop.
Creating and compiling a Rust X11 GUI application with Winit under NixOS

Creating and compiling a Rust GUI application under NixOS

Using a Nix-Shell

{ pkgs ? import <nixpkgs> { }, lib ? pkgs.stdenv.lib }:

pkgs.mkShell rec {
  name = "rust-env";

  buildInputs = with pkgs; [
    rustc
    cargo
    clang
    openssl
    pkgconfig
    xorg.libX11
    xorg.libXcursor
    xorg.libXrandr
    xorg.libXi
  ];

  LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}";
}

Enter the shell with nix-shell --pure. Always use a pure shell with development to ensure the expression actually works in other environments.

You can run the examples now, cargo run --example window

@bobbbay
Copy link

bobbbay commented Dec 1, 2021

This shell doesn't work for me - I'm getting:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: GlutinCreationError(CreationErrors([OsError("Could not create EGL display object"), OsError("`glXQueryExtensionsString` found no glX extensions")]))', /home/bob/.cargo/registry/src/github.com-1ecc6299db9ec823/egui_glium-0.15.0/src/epi_backend.rs:45:70
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

On Ubuntu + Nix under WSL.

@Stekke
Copy link

Stekke commented Jan 9, 2022

@bobbbay under windows 11? As far as I know it is not possible to create gui/opengl things in windows 10 using WSL. Win 11 WSL supports a wayland backend, but idk if gpu acceleration is supported yet? Can you run other GPU accelerated programs from Nix under WSL?

@bobbbay
Copy link

bobbbay commented Jan 9, 2022

Hi, I was on Win 10. I can run other programs from Nix under WSL with a GUI, but I have not tried other gpu-accelerated ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment