buildGoModule fails due to invalid go version

I’m currently trying to hack together my first package as a go module. I use the file dotcopy.nix, which looks like:

{ lib
, buildGoModule
, fetchFromGitHub
}:

buildGoModule rec {
  pname = "dotcopy";
  version = "0.2.9";

  src = fetchFromGitHub {
    owner = "firesquid6";
    repo = "dotcopy";
    rev = "v${version}";
    hash = "sha256-33cH8Yz2cMZzaoalniRjwy6ooAmy8rhQqf9ZeprpklA=";
  };

  vendorSha256 = lib.fakeSha256;

  meta = with lib; {
    description = "A linux dotfile manager";
    homepage = "https://dotcopy.firesquid.co";
    license = licenses.gpl3;
    longDescription = ''
      Dotcopy is a linux dotfile manager that allows you to "compile" your dotfiles to use the same template for multiple machines.
    '';
    maintainers = with maintainers; [ firesquid6 ];
  };
}

I also have a default.nix file in the same directory:

let
  nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-22.11";
  pkgs = import nixpkgs { config = {}; overlays = []; };
in

{
  dotcopy = pkgs.callPackage ./dotcopy.nix { };
}

I then run nix-build, and get the following behavior:

🕙 22:49:41 ✖  nix-build
these 2 derivations will be built:
  /nix/store/w0wwgs90rwlyny4gjkjfx90148z4hnxs-dotcopy-0.2.9-go-modules.drv
  /nix/store/ifr8dbnfh5dv5wd7jdda1cl887byc1rg-dotcopy-0.2.9.drv
building '/nix/store/w0wwgs90rwlyny4gjkjfx90148z4hnxs-dotcopy-0.2.9-go-modules.drv'...
unpacking sources
unpacking source archive /nix/store/v5mpqhxh81ij6ckwb1bsfsw6wkzwmj1v-source
source root is source
patching sources
configuring
building
go: errors parsing go.mod:
/build/source/go.mod:3: invalid go version '1.21.6': must match format 1.23
error: builder for '/nix/store/w0wwgs90rwlyny4gjkjfx90148z4hnxs-dotcopy-0.2.9-go-modules.drv' failed with exit code 1;
       last 8 log lines:
       > unpacking sources
       > unpacking source archive /nix/store/v5mpqhxh81ij6ckwb1bsfsw6wkzwmj1v-source
       > source root is source
       > patching sources
       > configuring
       > building
       > go: errors parsing go.mod:
       > /build/source/go.mod:3: invalid go version '1.21.6': must match format 1.23
       For full logs, run 'nix log /nix/store/w0wwgs90rwlyny4gjkjfx90148z4hnxs-dotcopy-0.2.9-go-modules.drv'.
error: 1 dependencies of derivation '/nix/store/ifr8dbnfh5dv5wd7jdda1cl887byc1rg-dotcopy-0.2.9.drv' failed to build

To me, it seems like buildGoModule is trying to compile my 1.21.6 module as 1.23, and failing because of that. Here is my project if the source code is the culprit: https://github.com/firesquid6/dotcopy.

No, the module is requesting to be compiled with go 1.23 or newer, but buildGoModule uses a 1.21.

But currently it seems as if nixpkgs only provides Go up to 1.22.

You will have to wait until 1.23 becomes available.

I believe the error actually isn’t saying you need Go version 1.23, as it’s not released yet. When setting the version in go.mod, Go expects (or did expect?) the format 1.xx, not 1.xx.x. Changing it to 1.21 should work.

That’s a really poorly worded error imo, I don’t see why they would use a future version as the example.

Found a solution. For some reason, fetchFromGithub was fetching an old version that was broken. Smells like a caching issue to me. I just used fetchzip to fetch the latest published source code from the github release and build from there. Here is the working package for anyone else running into this issue:

{ lib
, buildGoModule
, fetchzip
}:

buildGoModule rec {
  pname = "dotcopy";
  version = "0.2.14";

  src = fetchzip {
    url = "https://github.com/FireSquid6/dotcopy/archive/refs/tags/v${version}.zip";
    hash = "sha256-oVMsIZUJ7xOBwSlJF+RUIYG0dPMTZ3ftDd9cpRytl7w=";
  };

  doCheck = false;
  vendorSha256 = null;

  subPackages = [ "." ];

  meta = with lib; {
    description = "A linux dotfile manager";
    homepage = "https://dotcopy.firesquid.co";
    license = licenses.gpl3;
    longDescription = ''
      Dotcopy is a linux dotfile manager that allows you to "compile" your dotfiles to use the same template for multiple machines.
    '';
    maintainers = with maintainers; [ firesquid6 ];
  };
}

Given that the example in your link also uses 1.23 and the fact that 1, 2, 3 is just a monotonically increasing sequence of digits and the fact that go likes examples out of random numbers (see dates), I assume it’s just a random example, that just feels like it was meant to be a real version dude to the fact that it’s close to being a real released version soonish.