golangci-lint fails because it cannot find `go` in $PATH
This happens when running nix flake check.
golangci-lint............................................................Failed
- hook id: golangci-lint
- exit code: 3
WARN Failed to discover go env: failed to run 'go env -json GOCACHE GOROOT': exec: "go": executable file not found in $PATH
ERRO Running error: context loading failed: failed to load packages: failed to load packages: failed to load with go/packages: err: go command required, not found: exec: "go": executable file not found in $PATH: stderr:
~~This may be related to the fact that flakes do not admit environment variables~~. It goes well as a pre-commit-hook, thought.
still failing :(
same issue here
using
$ nix develop .#git-hooks --ignore-environment
I get into an env that has go, but I'm fairly certain it's from the previous shell
using
$ nix develop .#git-hooks --unset PATH
I can no longer use go
for reference, the git-hooks dev shell is just an alias for the one from pre-commit:
devShells.git-hooks = config.pre-commit.devShell;
using
golangci-lint = {
enable = true;
extraPackages = [ pkgs.go pkgs.which ];
};
I get the go binary which looks correct
$ which go
/nix/store/jyhpd4hgq672bm4m4s1r25zm1bx8vd44-go-1.23.2/bin/go
but nix flake check still fails because it can't find go during golangci-lint
I ended up writing a custom hook for all go tools, since I also needed to run some codegen before running golangci-lint
x-pre-commit-go =
let
pkg = pkgs.writeShellApplication {
name = "x-pre-commit-go";
runtimeInputs = [
pkgs.flatbuffers
pkgs.go
pkgs.golangci-lint
pkgs.just
pkgs.jq
pkgs.protobuf
pkgs.protoc-gen-go
pkgs.protoc-gen-go-grpc
pkgs.revive
];
text = ''
just gen-go
just golangci-lint
# just go-test
# just go-vet
# just go-revive
# just go-staticcheck
'';
};
in
{
enable = true;
package = pkg;
entry = "${lib.getExe pkg}";
pass_filenames = false;
};
I'm using just because I'm working with a big and complex multi-language monorepo and I like to avoid writing bespoke scripts in configs
@shackra maybe this will be useful to you too
extraPackages = [ pkgs.go pkgs.which ];butnix flake checkstill fails because it can't findgoduringgolangci-lint
@matdibu Adding it to extraPackages works fine for me, as it just adds it to the PATH of the check derivation. Can you still reproduce the failure with that specifically? I would be interested in figuring out what's going on. (Especially if it works now but not in November.)