Skip to content

Commit 6e15af6

Browse files
committed
[nix] Migrate linter installation to nix
1 parent 829646b commit 6e15af6

File tree

5 files changed

+57
-16
lines changed

5 files changed

+57
-16
lines changed

.github/workflows/ci.yml

+6-7
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,18 @@ jobs:
122122
# loki_password: ${{ secrets.LOKI_PASSWORD || '' }}
123123
Lint:
124124
runs-on: ubuntu-latest
125+
defaults:
126+
run:
127+
shell: nix develop --command bash -x {0}
125128
steps:
126129
- uses: actions/checkout@v4
127-
- uses: ./.github/actions/setup-go-for-project
130+
- uses: ./.github/actions/install-nix
128131
- name: Run static analysis tests
129-
shell: bash
130132
run: scripts/lint.sh
131133
- name: Run actionlint
132-
shell: bash
133-
run: scripts/actionlint.sh
134-
- uses: ./.github/actions/install-nix
134+
run: actionlint
135135
- name: Run shellcheck
136-
shell: bash
137-
run: nix develop --command bash -x scripts/shellcheck.sh
136+
run: scripts/shellcheck.sh
138137
buf-lint:
139138
name: Protobuf Lint
140139
runs-on: ubuntu-latest

flake.nix

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# Flake inputs
1010
inputs = {
11-
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2405.*.tar.gz";
11+
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2411.*.tar.gz";
1212
};
1313

1414
# Flake outputs
@@ -47,6 +47,8 @@
4747
self.packages.${system}.kind-with-registry # Script installing kind configured with a local registry
4848

4949
# Linters
50+
(import ./nix/golangci-lint.nix { inherit pkgs; })
51+
actionlint
5052
shellcheck
5153
] ++ lib.optionals stdenv.isDarwin [
5254
# macOS-specific frameworks

nix/golangci-lint.nix

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{ pkgs }:
2+
let
3+
# Helper functions to derive Go arch from Nix arch
4+
nixArchToGoArch = arch: {
5+
"x86_64" = "amd64";
6+
"aarch64" = "arm64";
7+
}.${arch} or arch;
8+
9+
# Split system into arch and os
10+
parseSystem = system:
11+
let
12+
parts = builtins.split "-" system;
13+
arch = builtins.elemAt parts 0;
14+
os = builtins.elemAt parts 2;
15+
in {
16+
osArch = "${os}-${nixArchToGoArch arch}";
17+
};
18+
19+
20+
# Update the following to change the version:
21+
22+
# 1.63.4 is the only binary release compatible with go1.23.
23+
# Newer versions are built with go1.24.x and consume memory until OOMkilled.
24+
lintVersion = "1.63.4";
25+
lintSHA256s = {
26+
"linux-amd64" = "01abb14a4df47b5ca585eff3c34b105023cba92ec34ff17212dbb83855581690";
27+
"linux-arm64" = "51f0c79d19a92353e0465fb30a4901a0644a975d34e6f399ad2eebc0160bbb24";
28+
"darwin-amd64" = "878d017cc360e4fb19510d39852c8189852e3c48e7ce0337577df73507c97d68";
29+
"darwin-arm64" = "a2b630c2ac8466393f0ccbbede4462387b6c190697a70bc2298c6d2123f21bbf";
30+
};
31+
32+
targetSystem = parseSystem pkgs.system;
33+
in
34+
pkgs.stdenv.mkDerivation {
35+
name = "golangci-lint-${lintVersion}";
36+
version = lintVersion;
37+
38+
src = pkgs.fetchurl {
39+
url = "https://github.com/golangci/golangci-lint/releases/download/v${lintVersion}/golangci-lint-${lintVersion}-${targetSystem.osArch}.tar.gz";
40+
sha256 = lintSHA256s.${targetSystem.osArch} or (throw "Unsupported system: ${pkgs.system}");
41+
};
42+
43+
installPhase = ''
44+
mkdir -p $out/bin
45+
cp -r ./golangci-lint $out/bin
46+
'';
47+
}

scripts/actionlint.sh

-7
This file was deleted.

scripts/lint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ fi
3232
TESTS=${TESTS:-"golangci_lint license_header require_error_is_no_funcs_as_params single_import interface_compliance_nil require_no_error_inline_func import_testing_only_in_tests"}
3333

3434
function test_golangci_lint {
35-
go install -v github.com/golangci/golangci-lint/cmd/[email protected]
3635
golangci-lint run --config .golangci.yml
3736
}
3837

@@ -41,6 +40,7 @@ function test_golangci_lint {
4140
# TESTS='license_header' ADDLICENSE_FLAGS="--debug" ./scripts/lint.sh
4241
_addlicense_flags=${ADDLICENSE_FLAGS:-"--verify --debug"}
4342
function test_license_header {
43+
# TODO(marun) Migrate to a nix package
4444
go install -v github.com/palantir/[email protected]
4545
local files=()
4646
while IFS= read -r line; do files+=("$line"); done < <(find . -type f -name '*.go' ! -name '*.pb.go' ! -name 'mock_*.go' ! -name 'mocks_*.go' ! -path './**/*mock/*.go' ! -name '*.canoto.go')

0 commit comments

Comments
 (0)