Specifying go version to use in buildGoModule

I am trying to build a docker container in CI using Nix with the following used to build the Go module itself:

  app = pkgs.buildGoModule {
    pname = "elections";
    version = "0.1.0";
    src = ./.;
    vendorHash = null;
  }; 

I’m using pkgs from a flake that specifies nixpkgs unstable. However, the default version of go is 1.22 and I need 1.23 for my project. How do I specify the Go version to use? I couldn’t find any documentation that covers this anywhere.
I looked at the documentation here: https://nixos.org/manual/nixpkgs/stable/#ssec-language-go but it was not helpful.

How can I find the answer to this kind of question in the future? Where should I be looking to figure out what options are available for a built in method like buildGoModule? Is the best information this 808 page document or am I missing something?

1 Like

I believe you can use buildGoxxxModule where xxx is the version you need. In this case, for Go 1.23:

  app = pkgs.buildGo123Module {
    pname = "elections";
    version = "0.1.0";
    src = ./.;
    vendorHash = null;
  };

You can also keep the buildGoModule input and just override that when calling the package:

  elections = callPackage package.nix {
    buildGoModule = buildGo123Module;
  };

Aside from this, you might be able to accomplish the same thing by overriding the go input of buildGoModule:

  elections = callPackage package.nix {
    buildGoModule = buildGoModule.override { go = go_1_23; };
  };

You should either search for how other people are doing this in nixpkgs or how the thing you’re looking for is being defined. In both cases, fuzzy searching will help you a lot, so I recommend you figure out how to use that with your favorite IDE, or you can use the GitHub search (which might not be as powerful).

For this particular question, I searched for buildGoModule = and I found a lot of instances of buildGoModule = buildGoxxxModule. A little more digging then led me to the go module definition, which has the go input that you can override.