-
Notifications
You must be signed in to change notification settings - Fork 115
/
flake.nix
262 lines (218 loc) · 6.7 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
{
description = "Nhost Hasura Auth";
inputs = {
nixops.url = "github:nhost/nixops";
nixpkgs.follows = "nixops/nixpkgs";
flake-utils.follows = "nixops/flake-utils";
nix-filter.follows = "nixops/nix-filter";
};
outputs = { self, nixops, nixpkgs, flake-utils, nix-filter }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [
nixops.overlays.default
(final: prev: {
nodejs = prev.nodejs_20;
})
];
pkgs = import nixpkgs {
inherit overlays system;
};
node-src = nix-filter.lib.filter {
root = ./.;
include = with nix-filter.lib;[
./package.json
./pnpm-lock.yaml
./tsconfig.build.json
./tsconfig.json
./audit-ci.jsonc
./jest.config.js
./.env.example
(inDirectory "migrations")
(inDirectory "src")
(inDirectory "types")
(inDirectory "email-templates")
(inDirectory "test")
];
exclude = with nix-filter.lib;[
./node_modules
];
};
src = nix-filter.lib.filter {
root = ./.;
include = with nix-filter.lib;[
(nix-filter.lib.matchExt "go")
(nix-filter.lib.matchExt "gotmpl")
./go.mod
./go.sum
./.golangci.yaml
./go/api/openapi.yaml
./go/api/server.cfg.yaml
./go/api/types.cfg.yaml
./go/sql/schema.sh
./go/sql/sqlc.yaml
./go/sql/query.sql
./go/sql/auth_schema_dump.sql
isDirectory
(inDirectory "email-templates")
(inDirectory "vendor")
];
};
nix-src = nix-filter.lib.filter {
root = ./.;
include = [
(nix-filter.lib.matchExt "nix")
];
};
node_modules-builder = pkgs.stdenv.mkDerivation {
inherit version;
pname = "node_modules-builder";
nativeBuildInputs = with pkgs; [
nodePackages.pnpm
cacert
];
src = nix-filter.lib.filter {
root = ./.;
include = [
./package.json
./pnpm-lock.yaml
];
};
buildPhase = ''
export PNPM_HOME=$TMP/.pnpm-home
pnpm install --frozen-lockfile
'';
installPhase = ''
mkdir -p $out
cp -r node_modules $out
'';
};
node_modules-prod = node_modules-builder.overrideAttrs (oldAttrs: {
name = "node_modules-prod";
buildPhase = ''
export PNPM_HOME=$TMP/.pnpm-home
pnpm install --frozen-lockfile --prod
'';
});
name = "hasura-auth";
description = "Nhost's Auth Service";
version = "0.0.0-dev";
module = "github.com/nhost/hasura-auth/go";
submodule = ".";
tags = [ ];
ldflags = [
"-X main.Version=${version}"
];
buildInputs = with pkgs; [ ];
nativeBuildInputs = with pkgs; [
makeWrapper
];
checkDeps = with pkgs; [
nhost-cli
mockgen
oapi-codegen
sqlc
postgresql_16_4-client
];
nixops-lib = nixops.lib { inherit pkgs; };
in
{
checks = {
nixpkgs-fmt = pkgs.runCommand "check-nixpkgs-fmt"
{
nativeBuildInputs = with pkgs;
[
nixpkgs-fmt
];
}
''
mkdir $out
nixpkgs-fmt --check ${nix-src}
'';
go-checks = nixops-lib.go.check {
inherit src submodule ldflags tags buildInputs nativeBuildInputs checkDeps;
};
node-checks = pkgs.runCommand "check-node"
{
nativeBuildInputs = with pkgs;
[
nodejs-slim_20
nodePackages.pnpm
cacert
];
}
''
echo ${src} > /dev/null # force rebuild if src changes
mkdir -p $TMPDIR/auth
cd $TMPDIR/auth
cp -r ${node-src}/* .
cp -r ${node-src}/.* .
ln -s ${node_modules-builder}/node_modules node_modules
export XDG_DATA_HOME=$TMPDIR/.local/share
export HOME=$TMPDIR
echo "➜ Running pnpm audit"
pnpx audit-ci --config ./audit-ci.jsonc
echo "➜ Running pnpm build"
pnpm build
echo "➜ Running pnpm test"
cp .env.example .env
pnpm test
mkdir -p $out
'';
};
devShells = flake-utils.lib.flattenTree rec {
default = nixops-lib.go.devShell {
buildInputs = with pkgs; [
go-migrate
nodejs
nodePackages.pnpm
] ++ checkDeps ++ buildInputs ++ nativeBuildInputs;
};
};
packages = flake-utils.lib.flattenTree rec {
node-auth = pkgs.stdenv.mkDerivation {
inherit version;
pname = "node-${name}";
buildInputs = with pkgs; [
pkgs.nodejs-slim_20
];
nativeBuildInputs = with pkgs; [
nodePackages.pnpm
];
src = node-src;
buildPhase = ''
ln -s ${node_modules-builder}/node_modules node_modules
pnpm build
'';
installPhase = ''
mkdir -p $out/bin
cp -r dist $out/dist
cp -r migrations $out/migrations
cp -r email-templates $out/email-templates
cp package.json $out/package.json
ln -s ${node_modules-prod}/node_modules $out/node_modules
'';
};
hasura-auth = nixops-lib.go.package {
inherit name submodule description src version ldflags nativeBuildInputs;
buildInputs = with pkgs; [
node-auth
] ++ buildInputs;
postInstall = ''
wrapProgram $out/bin/hasura-auth \
--suffix PATH : ${pkgs.nodejs-slim_20}/bin \
--prefix AUTH_NODE_SERVER_PATH : ${node-auth}
'';
};
docker-image = nixops-lib.go.docker-image {
inherit name version buildInputs;
contents = with pkgs; [
wget
];
package = hasura-auth;
};
default = hasura-auth;
};
}
);
}