Building go package with xorg dependancy

I’m trying to package lazysql as a nix derivation using pkgs.buildGoMod, but am getting the error X11/Xlib.h: No such file or directory. I tried adding libx11,, and pkgconfig to the nativeBuildInputs option and to buildInputs using overrideModAttrs, but still the same error both times. I can get it to build in a nix shell with the same packages though. any ideas what I could be missing?

pkgs.buildGoModule {
  name = "lazysql";
  src = pkgs.fetchFromGitHub {
    owner = "jorgerojas26";
    repo = "lazysql";
    rev = "v0.1.6";
    sha256 = "1qxYrzbtdVAxJ7WQf0IbMhGnF7tiw4gmqjAq7Ytd9z8=";
  nativeBuildInputs = with pkgs; [ pkg-config xorg.libX11 ];
  vendorHash = "sha256-tgD6qoCVC1ox15VPJWVvhe4yg3R81ktMuW2dsaU69rY=";

nativeBuildInputs is for things you need to run to build your application
buildInputs should be used for things you need to run your application.

Simply move libX11 into buildInputs

buildGoModule doesn’t have a buildInputs option, i tried adding it to buildInputs using override attrs but i got the same error

Went looking for an existing go package with external libraries as source and found

I believe you shouldn’t use overrideModAttrs since the error happens during the build in the primary derivation, not in the mod derivation where it fetches the dependencies.

copying that works, thank you for looking for that. I dont really understand how it works though, looking at the source for buildGoModule buildInputs isn’t listed in the args.

{ name ? "${args'.pname}-${args'.version}"
, src
, nativeBuildInputs ? [ ]
, passthru ? { }
, patches ? [ ]

  # A function to override the goModules derivation
, overrideModAttrs ? (_oldAttrs: { })

  # path to go.mod and go.sum directory
, modRoot ? "./"

  # vendorHash is the SRI hash of the vendored dependencies
  # if vendorHash is null, then we won't fetch any dependencies and
  # rely on the vendor folder within the source.
, vendorHash ? args'.vendorSha256 or (throw "buildGoModule: vendorHash is missing")
  # Whether to delete the vendor folder supplied with the source.
, deleteVendor ? false
  # Whether to fetch (go mod download) and proxy the vendor directory.
  # This is useful if your code depends on c code and go mod tidy does not
  # include the needed sources to build or if any dependency has case-insensitive
  # conflicts which will produce platform dependant `vendorHash` checksums.
, proxyVendor ? false

  # We want parallel builds by default
, enableParallelBuilding ? true

  # Do not enable this without good reason
  # IE: programs coupled with the compiler
, allowGoReference ? false


, meta ? { }

  # Not needed with buildGoModule
, goPackagePath ? ""

, ldflags ? [ ]

  # needed for buildFlags{,Array} warning
, buildFlags ? ""
, buildFlagsArray ? ""

, ...

You’re missing the last part:

, buildFlagsArray ? ""
, ...
  args = removeAttrs args' [ "overrideModAttrs" "vendorSha256" "vendorHash" ];

The args then gets passed to mkDerivation without changes.

1 Like