Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
134 lines (125 loc) · 4.35 KB
/
Copy pathflake.nix
File metadata and controls
134 lines (125 loc) · 4.35 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
{
description = "dev-kit";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
git-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
go-overlay = {
url = "github:purpleclay/go-overlay";
inputs.nixpkgs.follows = "nixpkgs";
inputs.git-hooks.follows = "git-hooks";
inputs.flake-utils.follows = "flake-utils";
};
gomod2nix = {
url = "github:nix-community/gomod2nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs = { self, nixpkgs, flake-utils, git-hooks, go-overlay, gomod2nix, ... }@inputs: {
lib.mkShell = { system, name ? "dev-shell", packages ? [], inputsFrom ? [], preCommitHooks ? {}, goVersion ? null, shellHook ? "", env ? {}, ... }:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
go-overlay.overlays.default
gomod2nix.overlays.default
];
};
lib = pkgs.lib;
mkDefaultAttrs = value:
if lib.isAttrs value then
builtins.mapAttrs (_: v: mkDefaultAttrs v) value
else
lib.mkDefault value;
defaultPkgs = with pkgs; [
curl
git
gnumake
jq
kind
kubectl
kubernetes-helm
(mdformat.withPlugins (ps: [ ps.mdformat-gfm ]))
shellcheck
shfmt
treefmt
unzip
yamlfmt
yq-go
];
defaultHooks = {
fmt = mkDefaultAttrs {
enable = true;
entry = "make fmt";
pass_filenames = false;
};
lint = mkDefaultAttrs {
enable = true;
entry = "make lint";
pass_filenames = false;
};
# Disabled by default: `make scan` resolves every dependency against
# the osv.dev API, which adds ~1min to any commit touching a manifest
# file. Vulnerability scanning belongs in CI, where it runs on a
# schedule and on every pull request without blocking a commit.
# Projects without a CI-side scan can opt back in per-project.
osv-scanner = mkDefaultAttrs {
enable = false;
entry = "make scan";
files = "\\.(mod|sum)$|requirements\\.txt$";
pass_filenames = false;
};
commitlint = mkDefaultAttrs {
enable = false;
entry = "${pkgs.commitlint}/bin/commitlint --edit";
stages = ["commit-msg"];
pass_filenames = false;
};
};
gitHooks = git-hooks.lib.${system}.run {
src = nixpkgs.path;
hooks = lib.recursiveUpdate defaultHooks preCommitHooks;
};
in
pkgs.mkShell {
inherit name env inputsFrom;
shellHook = gitHooks.shellHook + ''
[[ -f .git/hooks/pre-commit.legacy ]] && rm -v .git/hooks/pre-commit.legacy
'' + shellHook;
packages = defaultPkgs ++ packages ++ lib.optionals (goVersion != null) [
# go-overlay only carries versions it has a manifest for, and the
# overlay is pinned by flake.lock — so a freshly released Go patch
# does not exist here until the lock is refreshed. Without this the
# failure is `attribute '1.27.1' missing`, which points at the
# overlay's internals rather than at the fix, and it takes down every
# workflow at shell-evaluation time before any job runs.
(pkgs.go-bin.versions.${goVersion} or (throw ''
dev-kit: Go ${goVersion} is not in the locked go-overlay.
Available ${lib.versions.majorMinor goVersion}.x: ${
let
inMinor = builtins.filter
(v: lib.hasPrefix (lib.versions.majorMinor goVersion + ".") v)
(builtins.attrNames pkgs.go-bin.versions);
in
if inMinor == [] then "none" else lib.concatStringsSep ", " inMinor
}
Either refresh the overlay: nix flake update go-overlay
or set goVersion to a version listed above.
''))
pkgs.gotools
];
};
} // flake-utils.lib.eachDefaultSystem (system: {
devShells.default = self.lib.mkShell {
inherit system;
preCommitHooks = {
osv-scanner.enable = false;
commitlint.enable = true;
};
};
});
}