Failing to build a Go 1.22 application on master

I’m trying to package a Go application with Nix. I’m not a Go developer, so I might be missing something obvious. The expression that I’m starting from is minimal and follows examples seen elsewhere. This is on nixpkgs master because Go 1.22 is required.

Running nix build on this expression:

{ buildGoModule
, fetchFromGitHub
, lib
}:

buildGoModule rec {
  pname = "birdnet-go";
  version = "v0.5.2";

  src = fetchFromGitHub {
    owner = "tphakala";
    repo = pname;
    rev = "eafdfb492427eec3eecb4eb84d8530807ca89100";
    sha256 = lib.fakeHash;
  };

  vendorHash = lib.fakeHash;

  meta = with lib; {
    description = "AI solution for continuous avian monitoring and identification";
    homepage = "https://github.com/tphakala/birdnet-go";
    license = "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International";
    maintainers = with maintainers; [ vandenoever ];
    mainProgram = "birdnet";
  };
}

gives me

unpacking source archive /build/eafdfb492427eec3eecb4eb84d8530807ca89100.tar.gz                                                                                                              │ 
chmod: changing permissions of '/build/unpack/birdnet-go-eafdfb492427eec3eecb4eb84d8530807ca89100': Invalid argument                                                                         │ 
chmod: changing permissions of '/build/unpack/birdnet-go-eafdfb492427eec3eecb4eb84d8530807ca89100/.air.toml': Invalid argument                                                               │ 
chmod: changing permissions of '/build/unpack/birdnet-go-eafdfb492427eec3eecb4eb84d8530807ca89100/.devcontainer': Invalid argument                                                           │ 
chmod: changing permissions of '/build/unpack/birdnet-go-eafdfb492427eec3eecb4eb84d8530807ca89100/.devcontainer/devcontainer.json': Invalid argument                                         │ 
chmod: changing permissions of '/build/unpack/birdnet-go-eafdfb492427eec3eecb4eb84d8530807ca89100/.devcontainer/postCreateCommand.sh': Invalid argument                                      │ 
chmod: changing permissions of '/build/unpack/birdnet-go-eafdfb492427eec3eecb4eb84d8530807ca89100/.dockerignore': Invalid argument                                                           │ 

What could be causing chmod to fail with Invalid argument?

I don’t know what is causing these errors, but the following works for me (maybe your master is too old):

{
  inputs = { nixpkgs.url = "github:NixOS/nixpkgs/master"; };
  outputs = { self, nixpkgs }:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in {
      packages.${system}.default = pkgs.buildGoModule rec {
        pname = "birdnet-go";
        version = "v0.5.2";

        src = pkgs.fetchFromGitHub {
          owner = "tphakala";
          repo = pname;
          rev = "eafdfb492427eec3eecb4eb84d8530807ca89100";
          sha256 = "sha256-QqmLisDLwENDt7Xv+dFo+RE1H2Nkal2QDb7RDtuhVBQ=";
        };

        vendorHash = "sha256-aqcFcHLTTFJYvWdhEs72y3amQlrLw4q9tuAGQgQqCsg=";

        buildInputs = with pkgs; [ tensorflow-lite ];
      };
    };
}

Save it as flake or extract the derivation.

Cheers

The flake.nix you paste is what I would expect to work. But with nixpkgs master (d2d8db8cb7ff0d29be09cdb12a064c8bf73862a9) and nix 2.18.1, it gives:

@nix { "action": "setPhase", "phase": "unpackPhase" }
Running phase: unpackPhase
unpacking source archive /nix/store/h8qzlk5rmii8acxm3z1ckw9w2y79gbw7-source
cp: setting permissions for 'source': Invalid argument
do not know how to unpack source archive /nix/store/h8qzlk5rmii8acxm3z1ckw9w2y79gbw7-source
$ ls /nix/store/h8qzlk5rmii8acxm3z1ckw9w2y79gbw7-source
assets   CHANGELOG.md  cmd  Dockerfile  go.sum     internal  main.go   README.md       tailwind.config.js  views
AUTHORS  cliff.toml    doc  go.mod      input.css  LICENSE   Makefile  soundscape.wav  tawnyowl.wav

Building on NixOS 23.11 works fine after the requirement for a Go 1.22 is patched out:

{ buildGoModule, fetchFromGitHub, lib, tensorflow-lite }:

buildGoModule rec {
  pname = "birdnet-go";
  version = "v0.5.2";

  src = fetchFromGitHub {
    owner = "tphakala";
    repo = pname;
    rev = "eafdfb492427eec3eecb4eb84d8530807ca89100";
    sha256 = "sha256-QqmLisDLwENDt7Xv+dFo+RE1H2Nkal2QDb7RDtuhVBQ=";
  };

  vendorHash = "sha256-aqcFcHLTTFJYvWdhEs72y3amQlrLw4q9tuAGQgQqCsg=";

  patchPhase = ''
    sed -i 's/^go 1.22.2$/go 1.21.8/g' go.mod
  '';

  buildInputs = [ tensorflow-lite ];
}