-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
227 lines (220 loc) · 8.16 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
{
inputs = {
# Al packages
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
# Rust
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
# Rust tooling
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
# Linux server general optimizations
srvos = {
url = "github:nix-community/srvos";
inputs.nixpkgs.follows = "nixpkgs";
};
# Made to run at each commit and check
pre-commit-hooks = {
url = "github:cachix/git-hooks.nix";
inputs = {
nixpkgs.follows = "nixpkgs";
nixpkgs-stable.follows = "nixpkgs";
};
};
disko = {
#url = "github:jmbaur/disko/self-contained-deps";
url = "github:nix-community/disko"; # for disk generation
inputs.nixpkgs.follows = "nixpkgs";
};
# Go
gomod2nix = {
url = "github:nix-community/gomod2nix";
inputs = {
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixpkgs";
};
};
# Provides linux on temporary filesystems (wiped at reboot)
impermanence.url = "github:nix-community/impermanence";
# Kubernetes config file definitions strictly defined
kubenix = {
url = "github:hall/kubenix?ref=refs/tags/0.2.0";
inputs.nixpkgs.follows = "nixpkgs";
};
# OpenFaaS function software running in the container (like a proxy)
fwatchdog = {
url = "github:openfaas/of-watchdog";
flake = false;
};
enoslib = {
url = "git+https://gitlab.inria.fr/discovery/enoslib?ref=refs/tags/v9.2.0";
flake = false;
};
openfaas = {
# Since > v0.17.2 does a check at startup on checkip.amazonaws.com to start
# It seems OFaas sort of just not works without internet, more than 15 functions, more that 60 days... so for now let's stay on 17x
url = "github:openfaas/faas-netes?ref=refs/tags/0.17.2";
flake = false;
};
ebpf-netem.url = "github:volodiapg/ebpf-netem";
};
# Enable caching
nixConfig = {
extra-substituters = ["https://giraff.cachix.org"];
extra-trusted-public-keys = ["giraff.cachix.org-1:3sol29PSsWCh/7bAiRze+5Zq6OML02FDRH13K5i3qF4="];
};
outputs = inputs:
with inputs; let
inherit (self) outputs;
inherit (nixpkgs) lib;
extra = {
buildRustEnv = import ./rust.nix {inherit inputs;};
shellHook = system: shellName: let
pkgs = nixpkgs.legacyPackages.${system};
# packages is used as bash list in the following script
# deadnix: skip
packages =
outputs.devShells.${system}.${shellName}.buildInputs
++ outputs.devShells.${system}.${shellName}.nativeBuildInputs
++ outputs.devShells.${system}.${shellName}.propagatedBuildInputs;
in ''
# Add additional folders to to XDG_DATA_DIRS if they exists, which will get sourced by bash-completion
for p in ''${packages}; do
if [ -d "$p/share/bash-completion" ]; then
XDG_DATA_DIRS="$XDG_DATA_DIRS:$p/share"
fi
done
source ${pkgs.bash-completion}/etc/profile.d/bash_completion.sh
${outputs.checks.${system}.pre-commit-check.shellHook}
'';
};
subflake = path:
(import path).outputs inputs extra;
in
lib.foldl lib.recursiveUpdate {}
[
(subflake ./testbed/subflake.nix)
(subflake ./manager/subflake.nix)
(subflake ./iot_emulation/subflake.nix)
(subflake ./openfaas-functions/subflake.nix)
(flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
};
in {
apps.cachix = let
binPath = with pkgs;
lib.strings.makeBinPath (
[
nix
parallel
cachix
toybox
]
++ stdenv.initialPath
);
trace_pkgs = builtins.concatStringsSep " " (
pkgs.lib.mapAttrsToList
(name: output:
if (lib.strings.hasSuffix "vm" name) || (lib.strings.hasPrefix "fog_node" name) || (lib.strings.hasPrefix "market" name)
then ""
else "${output}")
outputs.packages.${system}
);
trace_apps = builtins.concatStringsSep " " (
pkgs.lib.mapAttrsToList
(name: output:
if (lib.strings.hasInfix "cachix" name) || (lib.strings.hasSuffix "Export" name)
then ""
else "${output.program}")
outputs.apps.${system}
);
script = pkgs.writeShellScript "cachix" ''
set -e
export PATH=${binPath}:$PATH
tmp=$(mktemp)
tmp2=$(mktemp)
parallel "(nix --extra-experimental-features 'nix-command flakes' path-info --json --derivation {} | jq -r 'map(.path)' | jq -r '.[]' | grep '/nix/store') >> $tmp" ::: ${trace_apps} ${trace_pkgs}
parallel -N1000 -a $tmp "(nix-store --query --requisites --include-outputs {} | grep '/nix/store') >> $tmp2"
cat $tmp2 >> $tmp
parallel -N1000 -a $tmp cachix push -j $(nproc --all) -m xz -c 9 giraff {}
rm $tmp
rm $tmp2
'';
in {
type = "app";
program = "${script}";
};
devShells.default = pkgs.mkShell {
shellHook = (extra.shellHook system) "default";
packages = with pkgs; [just cachix go];
};
formatter = pkgs.alejandra;
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
# Nix
alejandra.enable = true;
statix.enable = true;
deadnix = {
enable = true;
excludes = ["Cargo.nix"];
};
# Git (conventional commits)
commitizen.enable = true;
# Python
autoflake.enable = true;
isort.enable = true;
ruff.enable = true;
pyright.enable = true;
# Update the cache at each commit
zCachix = {
enable = false;
name = "push cachix";
entry = ''
sh -c 'nix run --extra-experimental-features "nix-command flakes" .#cachix'
'';
language = "system";
pass_filenames = false;
};
# manager
# manager = {
# enable = true;
# name = "rust (manager)";
# entry = "sh -c 'cd `git rev-parse --show-toplevel`/manager; nix develop -c .#manager just pre_commit'";
# language = "system";
# pass_filenames = false;
# };
# iot_emulation = {
# enable = true;
# name = "rust (iot_emulation)";
# entry = "sh -c 'cd iot_emulation; nix develop -c .#iot_emulation just pre_commit'";
# language = "system";
# pass_filenames = false;
# };
# # functions
# rustEcho = {
# enable = true;
# name = "rust (OpenFaaS functions)";
# entry = "sh -c 'cd openfaas-functions && nix develop .#openfaas_functions just pre_commit'";
# language = "system";
# pass_filenames = false;
# };
# Go
gofmt.enable = true;
revive.enable = true;
staticcheck.enable = true;
};
};
};
}
))
];
}