[solved] buildGoModule "predeclared any requires go1.18 or later"

Hi,

This has a solution, but I wanted to document it because it is a bit confusing, and I couldn’t find a solution by using the search engine, so maybe this will help someone out in the future!

The closest I found was Help packaging go-ethereum 1.10.23, built with go 1.18 but that didn’t have the simple fix.

I have encountered the following problem when trying to build GitHub - fhs/acme-lsp: Language Server Protocol tools for the acme text editor

# github.com/fhs/go-lsp-internal/lsp/protocol
vendor/github.com/fhs/go-lsp-internal/lsp/protocol/protocol.go:33:82: predeclared any requires go1.18 or later (-lang was set to go1.16; check go.mod)

with the following file:

with import <nixpkgs> { };
buildGoModule {
  pname = "acme-lsp";
  version = "0.11.0-unstable-2023-07";

  src = fetchFromGitHub {
    owner = "fhs";
    repo = "acme-lsp";
    rev = "c6ffdf3969420b94bd5b2d4fea27cb0e07831692";
    hash = "sha256-LxLjziEmU004l5hqcNqnNJ4StNSAzJxjce/u40I9TAo=";
  };

  vendorHash = "sha256-uNTqwJjtswtbPOmgIZDsr4fK6dTZSf4MxOyLNTD7lAQ=";
  subPackages = [ "cmd/L" "cmd/acme-lsp" ];
}

Turns out this was due to go 1.12 producing the vendor/modules.txt file differently (and this was confusing me as it is 1.12 not 1.16 like the error says).

If you change it to go 1.18 you will get a different vendor/modules.txt files which should work.The vendor/modules.txt gets ## explicit; go X.XX lines. (It also changes if you use go 1.14 but only to ## explicit and it won’t have the go versions pinned, and will probably run into predeclared any requires go1.18 or later (-lang was set to go1.16; check go.mod) - Stack Overflow). This will also of course change the vendorHash, but it should then build.