forked from akvorado/akvorado
-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
101 lines (97 loc) · 3.34 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
{
inputs = {
nixpkgs.url = "nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
asn2org = {
url = "github:vincentbernat/asn2org/gh-pages";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, asn2org }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
nodejs = pkgs.nodejs-18_x;
go = pkgs.go_1_21;
frontend = pkgs.buildNpmPackage.override { inherit nodejs; } {
name = "akvorado-frontend";
src = ./console/frontend;
npmDepsHash = builtins.readFile nix/npmDepsHash.txt;
installPhase = ''
mkdir $out
cp -r node_modules $out/node_modules
cp -r ../data/frontend $out/data
'';
};
backend = pkgs.buildGoModule.override { inherit go; } {
doCheck = false;
name = "akvorado";
src = ./.;
vendorHash = builtins.readFile nix/vendorHash.txt;
buildPhase = ''
sed 's|,[^,]*$||' ${asn2org}/asns.csv > orchestrator/clickhouse/data/asns.csv
cp -r ${frontend}/node_modules console/frontend/node_modules
cp -r ${frontend}/data console/data/frontend
touch .fmt-js~ .fmt.go~ .lint-js~ .lint-go~
find . -print0 | xargs -0 touch -d @0
make all \
MOCKGEN=${pkgs.mockgen}/bin/mockgen \
GOIMPORTS=${pkgs.gotools}/bin/goimports \
PIGEON=${pkgs.pigeon}/bin/pigeon \
REVIVE=${pkgs.coreutils}/bin/true
'';
# We do not use a wrapper to set SSL_CERT_FILE because, either a
# binary or a shell wrapper, it would pull the libc (~30M).
installPhase = ''
mkdir -p $out/bin $out/share/ca-certificates
cp bin/akvorado $out/bin/.
cp ${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt $out/share/ca-certificates/.
'';
};
in
rec {
apps = {
passthru = pkgs.lib.attrsets.mapAttrs
(name: value:
let
script = pkgs.writeShellScriptBin name value;
in
{
type = "app";
program = "${script}/bin/${name}";
})
rec {
update-vendorHash = ''
sha256=$(2>&1 nix build --no-link .#backend.goModules \
| ${pkgs.gnused}/bin/sed -nE "s/\s+got:\s+(sha256-.*)/\1/p")
[[ -z "$sha256" ]] || echo $sha256 > nix/vendorHash.txt
'';
update-npmDepsHash = ''
sha256=$(2>&1 nix build --no-link .#frontend.npmDeps \
| ${pkgs.gnused}/bin/sed -nE "s/\s+got:\s+(sha256-.*)/\1/p")
[[ -z "$sha256" ]] || echo $sha256 > nix/npmDepsHash.txt
'';
update = ''
${update-vendorHash}
${update-npmDepsHash}
'';
};
};
packages = {
inherit backend frontend;
default = backend;
};
# Activate with "nix develop"
devShells.default = pkgs.mkShell {
name = "akvorado-dev";
nativeBuildInputs = [
go
nodejs
pkgs.git
pkgs.curl
];
};
});
}