Example of NixOS package build and dev shell for Winit Programs #4568
wasv
started this conversation in
Show and tell
Replies: 1 comment
-
|
I want to share my default.nix file for a regular nix-build example, which doesn't depend on enabling the experimental nix-command. I am using vulkano but this should work with the wgpu vulkan backend. {
pkgs ? import <nixpkgs> { },
}:
with pkgs;
let
manifest = (lib.importTOML ./Cargo.toml).package;
in
rustPlatform.buildRustPackage {
pname = manifest.name;
version = manifest.version;
src = lib.cleanSource ./.;
cargoLock.lockFile = ./Cargo.lock;
strictDeps = true;
buildInputs = [
wayland
];
LD_LIBRARY_PATH = lib.makeLibraryPath [
libxkbcommon
vulkan-loader
];
nativeBuildInputs = [
makeBinaryWrapper
pkg-config
];
postFixup = ''
wrapProgram $out/bin/$pname --set LD_LIBRARY_PATH $LD_LIBRARY_PATH
'';
}LD_LIBRARY_PATH is a strict requirement for preventing a The shell.nix code simply brings over the LD_LIBRARY_PATH env variable, along with other dependencies and rust tools. {
pkgs ? import <nixpkgs> { },
}:
with pkgs;
let
defaultPackage = callPackage ./default.nix { };
in
mkShell {
inputsFrom = [ defaultPackage ];
LD_LIBRARY_PATH = defaultPackage.LD_LIBRARY_PATH;
packages = [
rustc
cargo
rustfmt
rust-analyzer
clippy
tombi
llvmPackages.lldb
];
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I was working with wgpu and winit in NixOS, and wasn't able to find an example of how to get the executable to find the dynamically loaded libraries in both a dev shell and a package build. So I wrote one.
The relevant portion of the package derivation:
And the dev shell:
The full text of my flake.nix is at
https://gist.github.com/wasv/5bb17e7b30953ac006069ddeae0da9ab
however that includes some opinionated choices like using fenix for pre-built rust binaries, available shell utilities, and using flakes in general.
Beta Was this translation helpful? Give feedback.
All reactions