-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathflake.nix
More file actions
179 lines (172 loc) · 6.12 KB
/
flake.nix
File metadata and controls
179 lines (172 loc) · 6.12 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
{
description = "The generic-device-plugin enables allocating generic Linux devices, such as serial devices, the FUSE device, or video cameras, to Kubernetes Pods";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
git-hooks-nix = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{ self, ... }@inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.git-hooks-nix.flakeModule
];
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];
perSystem =
{
pkgs,
system,
config,
...
}:
{
packages =
let
_version = builtins.getEnv "VERSION";
generic-device-plugin = pkgs.buildGoModule (finalAttrs: {
pname = "generic-device-plugin";
version = if _version != "" then _version else toString (self.rev or self.dirtyRev or "unknown");
src = ./.;
vendorHash = null;
checkFlags = [ "-skip=^TestE2E" ];
env.CGO_ENABLED = 0;
ldflags = [
"-s -w -X github.com/squat/generic-device-plugin/version.Version=${finalAttrs.version}"
];
meta = {
description = "The generic-device-plugin enables allocating generic Linux devices, such as serial devices, the FUSE device, or video cameras, to Kubernetes Pods";
mainProgram = "generic-device-plugin";
homepage = "https://github.com/squat/generic-device-plugin";
};
});
in
{
inherit generic-device-plugin;
default = generic-device-plugin;
}
// (builtins.listToAttrs (
map
(target: {
name = "generic-device-plugin-cross-${target.os}-${target.arch}";
value = generic-device-plugin.overrideAttrs (
_: oldAttrs: {
env = oldAttrs.env // {
GOOS = target.os;
GOARCH = target.arch;
CGO_ENABLED = 0;
};
checkPhase = false;
}
);
})
[
{
os = "linux";
arch = "amd64";
}
{
os = "linux";
arch = "arm64";
}
{
os = "linux";
arch = "arm";
}
]
));
pre-commit = {
check.enable = true;
settings = {
src = ./.;
hooks = {
actionlint.enable = true;
nixfmt-rfc-style.enable = true;
nixfmt-rfc-style.excludes = [ "vendor" ];
gofmt.enable = true;
gofmt.excludes = [ "vendor" ];
golangci-lint.enable = true;
golangci-lint.excludes = [ "vendor" ];
golangci-lint.extraPackages = [ pkgs.go ];
govet.enable = true;
govet.excludes = [ "vendor" ];
yamlfmt.enable = true;
yamlfmt.args = [
"--formatter"
"indentless_arrays=true"
];
yamlfmt.excludes = [
".github"
"vendor"
];
header = {
enable = true;
name = "Header";
entry =
let
headerCheck = pkgs.writeShellApplication {
name = "header-check";
text = ''
HEADER=$(cat ${./.header})
HEADER_LEN=$(wc -l ${./.header} | awk '{print $1}')
FILES=
for f in "$@"; do
for i in 0 1 2 3 4 5; do
FILE=$(tail -n +$i "$f" | ( head -n "$HEADER_LEN"; cat > /dev/null ) | sed "s/[0-9]\{4\}/YEAR/")
[ "$FILE" = "$HEADER" ] && continue 2
done
FILES="$FILES$f "
done
if [ -n "$FILES" ]; then \
printf 'the following files are missing the license header: %s\n' "$FILES"; \
exit 1
fi
'';
};
in
pkgs.lib.getExe headerCheck;
files = "\\.(go)$";
excludes = [ "vendor" ];
};
readme = {
enable = true;
name = "README.md";
entry =
let
readmeCheck = pkgs.writeShellApplication {
name = "readme-check";
text = ''
(go run ./... --help 2>&1 1>/dev/null || [ $? -eq 1 ]) | sed 's/\(Usage of\).*\(generic-device-plugin:\)/\1 \2/' > help.txt
go tool embedmd -d README.md
'';
};
in
pkgs.lib.getExe readmeCheck;
files = "^README\\.md$";
extraPackages = [ pkgs.go ];
};
};
};
};
devShells = {
default = pkgs.mkShell {
inherit (config.pre-commit.devShell) shellHook;
packages =
with pkgs;
[
go
kind
kubectl
]
++ config.pre-commit.settings.enabledPackages;
};
};
};
};
}