Open vanzef opened 6 years ago
The source of the issue is glutin. More details available in this closed issue.
I fixed the issue myself by building a simple nix package in the root of the cargo directory:
let
nixpkgs = import <nixpkgs> {};
inherit (nixpkgs) mesa libGL patchelf rustPlatform wayland xorg;
inherit (xorg) libX11 libXcursor libXi libXxf86vm;
in
rustPlatform.buildRustPackage rec {
pname = "spinning-square";
version = "0.1.0";
src = ./.;
cargoSha256 = "...";
buildInputs = [ patchelf ];
fixupPhase = ''
patchelf --set-rpath ${libGL}/lib:${mesa}/lib:${wayland}/lib:${libX11}/lib:${libXi}/lib:${libXcursor}/lib:${libXxf86vm}/lib \
$out/bin/spinning-square
'';
}
The most important part here is the patchelf
call where we modify the ELF binaries rpath to contain valid directions to all the listed directories. This should allow it run in both wayland and xorg on NixOS.
This can probably be marked as solved now. If the maintainer wishes to document this somewhere please do. Maybe even just a link to this issue in the readme so people on NixOS don't get stuck and quit trying.
Found this issue after going through the same struggle with backend errors, and I am also on NixOS. For others that find this, the package above is a good solution!
However. somewhere between now and then. glutin now requires libXrandr
, but that's just easily extending the patchelf
command to include it.
Here's my entire flake if anyone wants it.
{
description = "Basic Rust environment with toolchain and language server";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) mkShell rust mesa libGL patchelf rustPlatform wayland xorg;
inherit (xorg) libX11 libXcursor libXi libXxf86vm libXrandr;
pname = "simple-game";
version = "0.1.0";
nvimrc = ''local servers = { "rust_analyzer" }
local caps = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities());
for _, lsp in ipairs(servers) do
require("lspconfig")[lsp].setup {capabilities = caps}
end
vim.cmd("LspStart");'';
in
rec
{
# Executed by `nix build`
packages.default = rustPlatform.buildRustPackage {
inherit pname version;
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
buildInputs = [ patchelf ];
fixupPhase = ''
patchelf --set-rpath ${libGL}/lib:${mesa}/lib:${wayland}/lib:${libX11}/lib:${libXi}/lib:${libXcursor}/lib:${libXxf86vm}/lib:${libXrandr}/lib \
$out/bin/${pname}
'';
};
# Executed by `nix run`
apps.default = flake-utils.lib.mkApp { drv = packages.default; };
# Used by `nix develop`
devShells.default = mkShell {
buildInputs = with pkgs; [
cargo
rustc
clippy
rustfmt
rust-analyzer
pkg-config
];
RUST_SRC_PATH = "${rust.packages.stable.rustPlatform.rustLibSrc}";
shellHook = ''echo '${nvimrc}' > .nvimrc.lua'';
};
}
);
}
I am trying to build and run an example from piston.rs, here is the code fore reference:
but get error:
I am running NixOS, so problem may be with dynamically loading libraries. Is there a way to find out which libs do I need?
As far as I can understand the problem is in
XConnection::new
function:I've tried to explicitly "install" all mentioned libs via
nix-shell -p "[x11 gcc] ++ (with xorg; [libXcursor xrandr xinput libxcb])"
, but got the same error as above.