forked from nhost/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
164 lines (137 loc) · 4.33 KB
/
flake.nix
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
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/master";
nix-filter.url = "github:numtide/nix-filter";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils, nix-filter }:
flake-utils.lib.eachDefaultSystem (system:
let
name = "nhost";
version = pkgs.lib.fileContents ./VERSION;
description = "Nhost CLI";
pkgs = import nixpkgs {
inherit system;
overlays = [
(import ./nix/overlay.nix)
];
};
src = nix-filter.lib.filter {
root = ./.;
include = with nix-filter.lib;[
".golangci.yaml"
"go.mod"
"go.sum"
"ssl/.ssl/fullchain.pem"
"ssl/.ssl/privkey.pem"
(inDirectory "vendor")
(inDirectory "cmd/config/testdata")
isDirectory
(nix-filter.lib.matchExt "go")
];
};
nix-src = nix-filter.lib.filter {
root = ./.;
include = with nix-filter.lib;[
(matchExt "nix")
];
};
goCheckDeps = with pkgs; [
golangci-lint
gofumpt
golines
gqlgenc
govulncheck
richgo
];
buildInputs = with pkgs; [
];
nativeBuildInputs = with pkgs; [
go
clang
];
tags = [ ];
ldflags = [
"-X main.Version=${version}"
];
in
{
checks = flake-utils.lib.flattenTree rec {
nixpkgs-fmt = pkgs.runCommand "check-nixpkgs-fmt"
{
nativeBuildInputs = with pkgs;
[
nixpkgs-fmt
];
}
''
mkdir $out
nixpkgs-fmt --check ${nix-src}
'';
go = pkgs.runCommand "gotests"
{
nativeBuildInputs = goCheckDeps ++ buildInputs ++ nativeBuildInputs;
}
''
export GOLANGCI_LINT_CACHE=$TMPDIR/.cache/golangci-lint
export GOCACHE=$TMPDIR/.cache/go-build
export GOMODCACHE="$TMPDIR/.cache/mod"
export GOPATH="$TMPDIR/.cache/gopath"
echo "➜ Source: ${src}"
echo "➜ Running go generate ./... and checking sha1sum of all files"
mkdir -p $TMPDIR/generate
cd $TMPDIR/generate
cp -r ${src}/* .
chmod +w -R .
go generate ./...
find . -type f ! -path "./vendor/*" -print0 | xargs -0 sha1sum > $TMPDIR/sum
cd ${src}
sha1sum -c $TMPDIR/sum || (echo "❌ ERROR: go generate changed files" && exit 1)
echo "➜ Running code formatters, if there are changes, fail"
golines -l --base-formatter=gofumpt . | diff - /dev/null
echo "➜ Checking for vulnerabilities"
govulncheck ./...
echo "➜ Running golangci-lint"
golangci-lint run \
--timeout 300s \
./...
echo "➜ Running tests"
richgo test \
-tags="${pkgs.lib.strings.concatStringsSep " " tags}" \
-ldflags="${pkgs.lib.strings.concatStringsSep " " ldflags}" \
-v ./...
mkdir $out
'';
};
devShells = flake-utils.lib.flattenTree rec {
default = pkgs.mkShell {
buildInputs = with pkgs; [
goreleaser
certbot-full
] ++ goCheckDeps ++ buildInputs ++ nativeBuildInputs;
};
cibuild = pkgs.mkShell {
buildInputs = with pkgs; [
go
goreleaser
];
};
};
packages = flake-utils.lib.flattenTree rec {
cli = pkgs.buildGoModule {
inherit src version ldflags buildInputs nativeBuildInputs;
pname = name;
vendorSha256 = null;
doCheck = false;
CGO_ENABLED = 1;
meta = with pkgs.lib; {
description = description;
homepage = "https://github.com/nhost/cli";
maintainers = [ "nhost" ];
platforms = platforms.linux ++ platforms.darwin;
};
};
};
}
);
}