Amethyst: [BUG] Nixos support

Created on 12 Aug 2019  Â·  3Comments  Â·  Source: amethyst/amethyst

Description

A clear and concise description of what the bug is.

Reproduction Steps

  1. default.nix
let
  moz_overlay = import (builtins.fetchTarball
  "https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz");
  nixpkgs = import <nixpkgs> { overlays = [ moz_overlay ]; };
  ruststable = (nixpkgs.latest.rustChannels.stable.rust.override {
    extensions = [ "rust-src" "rls-preview" "rust-analysis" "rustfmt-preview" ];
  });
in with nixpkgs;
stdenv.mkDerivation {
  name = "rust";
  buildInputs = [
    openssl
    nasm
    rustup
    ruststable
    pkgconfig
    cmake
    zlib
    xorg.libX11
    xorg.libXcursor
    alsaLib
    freetype
    expat
  ];

  shellHook = ''
    export OPENSSL_DIR="${openssl.dev}"
    export OPENSSL_LIB_DIR="${openssl.out}/lib"
  '';
}
  1. Follow Pong example in docs til https://book.amethyst.rs/stable/pong-tutorial/pong-tutorial-01.html#setting-up-basic-rendering
  2. Use nix-shell to create environment

What You Expected to Happen

Blank screen titled pong!

What Actually Happened

Finished dev [unoptimized + debuginfo] target(s) in 0.14s
     Running `target/debug/pong`
thread 'main' panicked at 'Failed to initialize any backend! Wayland status: NoCompositorListening X11 status: LibraryOpenError(OpenError { kind: Library, detail: "opening library failed (libXcursor.so.1: cannot open shared object file: No such file or directory); opening library failed (libXcursor.so: cannot open shared object file: No such file or directory)" })', /home/emiller/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.19.2/src/platform/linux/mod.rs:459:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

Your Environment

  1. Operating System
    Nixos
  2. Operating System Version
    unstable
  3. Version of Amethyst
    0.12

I would like to help provide support for nix for the project with some guidance!

normal discussing documentation bug

Most helpful comment

2013 was merged, I think this can be closed

All 3 comments

This is an issue with anything using winit on NixOS, not specific to Amethyst.
Though I'm not sure _exactly_ what the cause is, I know that it can be fixed (temporarily / per-build) by using patchelf on the file (e.g. target/debug/pong).
(patchelf seems to be available by default in a nix-shell, but not normally otherwise)
Specifically, though there's probably a better or faster method—I seem to recall something involving nix-repl that generated paths like this—I had to find the paths in /nix/store that contained the files it was looking for and couldn't find (find /nix/store -name libXcursor.so.1/etc), choose one of the results, run something like patchelf --set-rpath /nix/store/…-libXcursor-1.2.0/lib:/nix/store/… ./target/debug/pong, and then cargo run again.
If it complained about the same library (something about ELF types or something came up often), I chose a different instance of the library I had in /nix/store and did it again; if it complained about a different one, I added that to the list.
After five or six of these, the example I was trying to get working (from a different library using winit) ran, and it seemed to work fine.

Edit: The method involving nix repl is described in the Extra Dynamic Libraries section on https://nixos.wiki/wiki/Packaging/Binaries.

I've been using this as shell.nix for my projects:

let
  mozilla = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
  nixpkgs = import <nixpkgs> { overlays = [ mozilla ]; };
in

  with nixpkgs;

  mkShell {
    buildInputs = [
      alsaLib
      cmake
      freetype
      latest.rustChannels.stable.rust
      expat
      openssl
      pkgconfig
      python3
      vulkan-validation-layers
      xlibs.libX11
    ];

    APPEND_LIBRARY_PATH = stdenv.lib.makeLibraryPath [
      vulkan-loader
      xlibs.libXcursor
      xlibs.libXi
      xlibs.libXrandr
    ];

    shellHook = ''
      export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$APPEND_LIBRARY_PATH"
      export RUSTFLAGS="-C target-cpu=native"
    '';
  }

This issue can probably be closed, I could PR a note in the documentation on how to use Amethyst on NixOS.

2013 was merged, I think this can be closed

Was this page helpful?
0 / 5 - 0 ratings