I want to work with the go module “go-sdl2” (link below) but I’m having trouble putting together a .nix-file. I’ve tried with the below but it fails.
Manual configuration:
{ pkgs ? (import <nixpkgs> {}).pkgs }:
with pkgs;
mkShell {
buildInputs = [
go
SDL2
pkg-config
];
#PKG_CONFIG_PATH=""$PKG_CONFIG_PATH{pkgs.sdl2}/lib
#echo $PKG_CONFIG_PATH
shellHook = ''
LD_LIBRARY_PATH=${pkgs.SDL2}/lib
echo $LD_LIBRARY_PATH
go get -v github.com/veandco/go-sdl2/sdl
'';
}
Steps to reproduce:
1: Copy the above code into shell.nix
2: run ‘nix-shell shell.nix’
Expected result: Entering the nix-shell succeeds in loading the module.
Received result:
go: downloading github.com/veandco/go-sdl2 v0.4.25
github.com/veandco/go-sdl2/sdl
# github.com/veandco/go-sdl2/sdl
In file included from _cgo_export.c:4:
events.go:4:10: fatal error: sdl_wrapper.h: No such file or directory
compilation terminated.
The issue is that ‘go get’ doesn’t look inside the gopath where the file is located (in my case at /home/$USER/go/github.com/veandco/go-sdl2@v0.4.24/sdl/").
How do I fix this and load the module? I looked into buildGoModule but ran into a wall quickly with sha256s and if it’s even relevant in my case (as I’m looking to import a module, not publish one).
{ }: with import <nixpkgs>{};
buildGoModule {
pname = "sdl2-go";
version = "0.4.25";
src = fetchFromGitHub {
owner = "veandco";
repo = "go-sdl2";
rev = "v0.4.25";
sha256 = "sha256-3t/f1pdNdlFn6sJ+/FOJuhgZdfRJFjWA+qsdvO4Cc8s=";
};
vendorSha256 = "sha256-yqYY6/4W6oCrAwl3RrZl09qeH2qj87R2cpdrVC3PLvo=";
meta = with lib; {
description = "go-sdl2 is SDL2 wrapped for Go users.";
homepage = "https://github.com/veandco/go-sdl2";
};
}
However, this leads into pkg-config errors:
# pkg-config --cflags -- sdl2
Package sdl2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `sdl2.pc'
to the PKG_CONFIG_PATH environment variable
No package 'sdl2' found
pkg-config: exit status 1