forked from nhost/hasura-storage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
172 lines (142 loc) · 4.81 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
{
description = "Nhost Hasura Storage";
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
localOverlay = import ./nix/overlay.nix;
overlays = [ localOverlay ];
pkgs = import nixpkgs {
inherit system overlays;
};
go-src = nix-filter.lib.filter {
root = ./.;
};
nix-src = nix-filter.lib.filter {
root = ./.;
include = [
(nix-filter.lib.matchExt "nix")
];
};
buildInputs = with pkgs; [
vips
];
nativeBuildInputs = with pkgs; [
go
clang
pkg-config
];
name = "hasura-storage";
version = nixpkgs.lib.fileContents ./VERSION;
module = "github.com/nhost/hasura-storage";
tags = "integration";
ldflags = ''
-X ${module}/controller.buildVersion=${version} \
'';
in
{
checks = {
nixpkgs-fmt = pkgs.runCommand "check-nixpkgs-fmt"
{
nativeBuildInputs = with pkgs;
[
nixpkgs-fmt
];
}
''
mkdir $out
nixpkgs-fmt --check ${nix-src}
'';
golangci-lint = pkgs.runCommand "golangci-lint"
{
nativeBuildInputs = with pkgs; [
clang
golangci-lint
] ++ buildInputs ++ nativeBuildInputs;
}
''
export GOLANGCI_LINT_CACHE=$TMPDIR/.cache/golangci-lint
export GOCACHE=$TMPDIR/.cache/go-build
export GOMODCACHE="$TMPDIR/.cache/mod"
mkdir $out
cd $out
cp -r ${go-src}/* .
golangci-lint run \
--build-tags=${tags} \
--timeout 300s
'';
gotests = pkgs.runCommand "gotests"
{
nativeBuildInputs = with pkgs; [
docker-client
docker-compose
richgo
] ++ buildInputs ++ nativeBuildInputs;
}
''
export GOCACHE=$TMPDIR/.cache/go-build
export GOMODCACHE="$TMPDIR/.cache/mod"
mkdir $out
cd $out
cp -r ${go-src}/* .
export HASURA_AUTH_BEARER=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE5ODAwNTYxNTAsImh0dHBzOi8vaGFzdXJhLmlvL2p3dC9jbGFpbXMiOnsieC1oYXN1cmEtYWxsb3dlZC1yb2xlcyI6WyJhZG1pbiJdLCJ4LWhhc3VyYS1kZWZhdWx0LXJvbGUiOiJhZG1pbiIsIngtaGFzdXJhLXVzZXItaWQiOiJhYjViYTU4ZS05MzJhLTQwZGMtODdlOC03MzM5OTg3OTRlYzIiLCJ4LWhhc3VyYS11c2VyLWlzQW5vbnltb3VzIjoiZmFsc2UifSwiaWF0IjoxNjY0Njk2MTUwLCJpc3MiOiJoYXN1cmEtYXV0aCIsInN1YiI6ImFiNWJhNThlLTkzMmEtNDBkYy04N2U4LTczMzk5ODc5NGVjMiJ9.OMVYu-30oOuUNZeSbzhP0u0pq5bf-U2Z49LWkqr3hyc
export TEST_S3_ACCESS_KEY=5a7bdb5f42c41e0622bf61d6e08d5537
export TEST_S3_SECRET_KEY=9e1c40c65a615a5b52f52aeeaf549944ec53acb1dff4a0bf01fb58e969f915c8
export GIN_MODE=release
go test \
-tags=${tags} \
-ldflags="${ldflags}" \
-v ./...
'';
};
devShells = flake-utils.lib.flattenTree rec {
default = pkgs.mkShell {
buildInputs = with pkgs; [
nixpkgs-fmt
golangci-lint
docker-client
docker-compose
go-migrate
gnumake
gnused
richgo
ccls
mockgen
] ++ buildInputs ++ nativeBuildInputs;
};
};
packages = flake-utils.lib.flattenTree rec {
hasuraStorage = pkgs.callPackage ./nix/hasura-storage.nix {
inherit name version ldflags tags buildInputs nativeBuildInputs;
};
dockerImage = pkgs.dockerTools.buildLayeredImage {
name = name;
tag = version;
created = "now";
contents = [
pkgs.cacert
] ++ buildInputs;
config = {
Env = [
"TMPDIR=/"
"MALLOC_ARENA_MAX=2"
];
Entrypoint = [
"${self.packages.${system}.hasuraStorage}/bin/hasura-storage"
];
};
};
default = hasuraStorage;
};
apps = flake-utils.lib.flattenTree {
hasuraStorage = self.packages.${system}.hasuraStorage;
golangci-lint = pkgs.golangci-lint;
default = self.packages.${system}.hasuraStorage;
};
}
);
}