blob: 5d584e215c03fae84c90ce11bac52fb419ed34ed (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
flake-utils.url = "github:numtide/flake-utils";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
pre-commit-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
treefmt-nix,
flake-utils,
pre-commit-hooks,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
ciPackages = with pkgs; [
go # Need that obviously
gofumpt # Go formatter
golangci-lint # Local/CI linter
gotestsum # Pretty tester
goperf # Go performance suite
];
devPackages = with pkgs; [
gopls
gotools
];
in
{
formatter = treefmtEval.config.build.wrapper;
checks = {
# Throws an error if any of the source files are not correctly formatted
# when you run `nix flake check --print-build-logs`. Useful for CI
treefmt = treefmtEval.config.build.check self;
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
format = {
enable = true;
name = "Format with treefmt";
pass_filenames = true;
entry = "${treefmtEval.config.build.wrapper}/bin/treefmt";
stages = [
"pre-commit"
"pre-push"
];
};
golangci-lint = {
enable = true;
package = pkgs.golangci-lint;
pass_filenames = true;
stages = [ "pre-push" ];
};
unit-tests-go = {
enable = true;
name = "Run unit tests";
entry = "gotestsum --format testdox ./...";
pass_filenames = false;
stages = [ "pre-push" ];
types = [ "go" ];
};
};
};
};
devShells = {
default = pkgs.mkShell {
buildInputs =
[ ] ++ ciPackages ++ devPackages ++ self.checks.${system}.pre-commit-check.enabledPackages;
shellHook = ''
${self.checks.${system}.pre-commit-check.shellHook}
'';
};
ci = pkgs.mkShell {
buildInputs = [ ] ++ ciPackages;
CI = true;
shellHook = ''
echo "Entering CI shell. Only essential CI tools available."
'';
};
};
}
);
}
|