-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
222 lines (200 loc) · 6.78 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
{
description = "Lifeline Server setup";
nixConfig = {
# builds microvm.nix kernels daily
extra-substituters = [ "https://nix-serve.hq.c3d2.de" ];
extra-trusted-public-keys = [ "nix-serve.hq.c3d2.de:KZRGGnwOYzys6pxgM8jlur36RmkJQ/y8y62e52fj1ps=" ];
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
dns = {
url = "github:kirelagin/dns.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
mvn2nix = {
url = "github:fzakaria/mvn2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
microvm = {
url = "github:astro/microvm.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, sops-nix, dns, mvn2nix, microvm }:
let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
inherit (pkgs) lib;
commonAttrs = {
inherit system;
extraArgs = { flake = self; inherit system dns; };
};
commonModules = [
./deployment/modules/nix.nix
./deployment/modules/default.nix
#sops-nix.nixosModules.sops
#./deployment/modules/sops.nix
#./deployment/modules/monitoring/client.nix
#nix-deploy-git.nixosModule
#./deployment/modules/nix-deploy-git.nix
];
in
rec {
nixosConfigurations = {
## HOST
lifeline = nixpkgs.lib.nixosSystem (lib.mergeAttrs commonAttrs {
modules = commonModules ++ [
microvm.nixosModules.host
./deployment/hosts/lifeline/configuration.nix
./deployment/modules/afg.nix
./deployment/modules/nginx/afg.nix
./deployment/modules/dns.nix
./deployment/modules/restic/server.nix
#./deployment/modules/binarycache/server.nix
#./deployment/modules/monitoring/server.nix
#./deployment/modules/jenkins.nix
];
});
## VMs
afg-staging = nixpkgs.lib.nixosSystem (lib.mergeAttrs commonAttrs {
modules = commonModules ++ [
microvm.nixosModules.microvm
./deployment/hosts/afg-staging/configuration.nix
{ nixpkgs.overlays = [ self.overlay ]; }
./deployment/modules/afg.nix
];
});
mqtt = nixpkgs.lib.nixosSystem (lib.mergeAttrs commonAttrs {
modules = commonModules ++ [
microvm.nixosModules.microvm
./deployment/hosts/mqtt/configuration.nix
## TODO this modules should not be required!
{ nixpkgs.overlays = [ self.overlay ]; }
./deployment/modules/afg.nix
];
});
};
legacyPackages.${system} = { inherit pkgs; };
overlay = final: prev: {
inherit (self.packages.${system}) afg-fullstack;
};
packages.${system} =
let
## The packages provided by the inputs of this flake
inherit pkgs;
in {
## Tools for devops
updateBackendDeps = pkgs.callPackage ./backend/nix/tools/updated-deps.nix {
inherit (mvn2nix.legacyPackages.${system}) mvn2nix;
};
cypress = import ./frontend/nix/tools/cypress/override.nix { inherit pkgs; };
## Derivations provided by this repo
inherit (pkgs.callPackages ./frontend/submission/nix {})
afg-submission-deps
afg-submission-staticHTML;
afg-backend = pkgs.callPackage ./backend/nix {
inherit (mvn2nix.legacyPackages.${system}) buildMavenRepositoryFromLockFile;
inherit pkgs;
};
afg-fullstack = self.packages.${system}.afg-backend.override {
patchPublic = self.packages.${system}.afg-submission-staticHTML;
};
} // builtins.foldl' (result: hostName:
let
host = self.nixosConfigurations.${hostName}
.extendModules {
modules = [ {
services.afg-frontend.configName = nixpkgs.lib.mkForce "staging-local.edn";
} ];
};
inherit (host) config;
inherit (config.microvm) declaredRunner;
in
if config ? microvm && config.microvm ? declaredRunner
then result // {
"${hostName}" = pkgs.writeScriptBin hostName ''
#! ${pkgs.runtimeShell} -e
# Setup tuntap interfaces
for IFACE in $(cat ${declaredRunner}/share/microvm/tap-interfaces); do
if ! [ -e /sys/class/net/$IFACE ]; then
sudo ip tuntap add name $IFACE mode tap user $USER
sudo ip a a 10.0.0.1/24 dev $IFACE
fi
sudo ip l s $IFACE up
done
# Make a working env
TMPDIR=$(mktemp -d)
echo TMPDIR: $TMPDIR
pushd "$TMPDIR"
${declaredRunner}/bin/microvm-run || true
popd
rm -r "$TMPDIR"
for IFACE in $(cat ${declaredRunner}/share/microvm/tap-interfaces); do
sudo ip tuntap del name $IFACE mode tap
done
'';
}
else result
) {} (builtins.attrNames self.nixosConfigurations);
checks.${system}.submission-integration = with pkgs;
let
testResults = runCommandNoCC "afg-submission-integration-tests" {
nativeBuildInputs = with self.packages.${system}; [
curl gnupg
self.packages.${system}.afg-fullstack
cypress
];
} ''
export HOME=$(mktemp -d)
mkdir backend
pushd backend
cp -r ${./backend/data} data
gpg --import data/keys/test.sec.gpg
chmod -R u+w data
CONFIG=data/config/test.edn afg-backend &
popd
while ! curl -s http://localhost:4000; do
echo Wait for backend
sleep 1
done
mkdir -p frontend/submission $out
cd frontend/submission
cp ${./frontend/submission/cypress.json} cypress.json
cp -r ${./frontend/submission/cypress} cypress
chmod -R u+w cypress
export CYPRESS_BASE_URL=http://localhost:4000
set +e
cypress run
echo $? > $out/result
set -e
if [ -e cypress/results ]; then
cp -r cypress/results $out/
fi
if [ -e cypress/screenshots ]; then
cp -r cypress/screenshots $out/
fi
'';
in runCommandNoCC "afg-submission-integration-check" {} ''
echo See test results at ${testResults}
ln -s ${testResults} $out
RESULT=$(cat "${testResults}/result")
'';
# `nix develop`
devShell.${system} = with nixpkgs.legacyPackages.${system}; mkShell {
nativeBuildInputs = [
# backend
leiningen
gnupg
# frontend
nodejs yarn
self.packages.${system}.cypress
# doc
mdbook mdbook-mermaid
];
};
};
}