ALPHA: wire is a tool to deploy nixos systems
wire.althaea.zone/
1# SPDX-License-Identifier: AGPL-3.0-or-later
2# Copyright 2024-2025 wire Contributors
3
4{
5 lib,
6 inputs,
7 ...
8}:
9let
10 inherit (lib)
11 mapAttrsToList
12 flatten
13 ;
14in
15{
16 config.perSystem =
17 {
18 pkgs,
19 self',
20 system,
21 ...
22 }:
23 let
24 benchDirFileset = lib.fileset.toSource {
25 root = ../..;
26 fileset = lib.fileset.union ./. (
27 lib.fileset.fileFilter (
28 file: (file.hasExt "nix") || (file.hasExt "txt") || (file.hasExt "lock")
29 ) ../.
30 );
31 };
32
33 nodes =
34 builtins.listToAttrs (
35 builtins.map (index: {
36 value = {
37 imports = [
38 ./vm.nix
39 ];
40
41 _module.args = {
42 index = builtins.toString index;
43 };
44 };
45 name = "node_${builtins.toString index}";
46 }) (lib.range 0 (import ./num-nodes.nix))
47 )
48 // {
49 deployer = {
50 imports = [
51 ./vm.nix
52 ];
53
54 environment.systemPackages = [
55 pkgs.git
56
57 (pkgs.writeShellScriptBin "setup-benchmark" ''
58 mkdir -p $HOME/wire
59 cp -r ${benchDirFileset}/*-source/* $HOME/wire
60
61 cp -r $HOME/wire/bench/wire-flake $HOME/wire-flake
62 cp -r $HOME/wire/bench/colmena-flake $HOME/colmena-flake
63
64 chmod -R +w $HOME/*
65
66 cd $HOME/wire
67 git init .
68 git add -A
69 '')
70
71 (pkgs.writeShellScriptBin "run-benchmark" ''
72 bench_dir=$HOME/wire/bench
73
74 wire_args="apply test --path $bench_dir/wire -vv --ssh-accept-host -p 10"
75 wire_args_flake="apply test --path $HOME/wire-flake -vv --ssh-accept-host -p 10"
76
77 colmena_args="apply test --config $bench_dir/colmena/hive.nix -v -p 10"
78 colmena_args_flake="apply test --config $HOME/colmena-flake/flake.nix -v -p 10"
79
80 ${lib.getExe pkgs.hyperfine} --warmup 1 --show-output --runs 5 \
81 --export-markdown stats.md \
82 --export-json run.json \
83 "${lib.getExe self'.packages.wire-small} $wire_args_flake" -n "wire@HEAD - flake" \
84 "${lib.getExe' inputs.colmena_benchmarking.packages.x86_64-linux.colmena "colmena"} $colmena_args_flake" \
85 -n "colmena@pinned - flake" \
86 "${lib.getExe self'.packages.wire-small} $wire_args" -n "wire@HEAD - hive.nix"
87 '')
88 ];
89
90 _module.args = {
91 index = "deployer";
92 };
93 };
94 };
95
96 evalConfig = import (pkgs.path + "/nixos/lib/eval-config.nix");
97
98 evalVM =
99 module:
100 evalConfig {
101 inherit system;
102 modules = [ module ];
103 };
104 in
105 {
106 checks.bench = pkgs.testers.runNixOSTest {
107 inherit nodes;
108
109 name = "benchmark";
110
111 defaults =
112 _:
113 let
114 # hive = builtins.scopedImport {
115 # __nixPath = _b: null;
116 # __findFile = _path: name: if name == "nixpkgs" then pkgs.path else throw "oops!!";
117 # } "${injectedFlakeDir}/${path}/hive.nix";
118
119 # fetch **all** dependencies of a flake
120 # it's called fetchLayer because my naming skills are awful
121 fetchLayer =
122 input:
123 let
124 subLayers = if input ? inputs then map fetchLayer (builtins.attrValues input.inputs) else [ ];
125 in
126 [
127 input.outPath
128 ]
129 ++ subLayers;
130 in
131 {
132 virtualisation.additionalPaths = flatten [
133 (mapAttrsToList (_: val: (evalVM val).config.system.build.toplevel.drvPath) nodes)
134 (mapAttrsToList (_: fetchLayer) inputs)
135 ];
136
137 nix.settings.experimental-features = [
138 "nix-command"
139 "flakes"
140 ];
141 };
142 node.specialArgs = {
143 snakeOil = import "${pkgs.path}/nixos/tests/ssh-keys.nix" pkgs;
144 inherit (self'.packages) wire-small-dev;
145 };
146 skipTypeCheck = true;
147 testScript = ''
148 start_all()
149
150 for i in range(0,${builtins.toString (import ./num-nodes.nix)}):
151 machine = globals().get(f"node_{i}")
152 machine.wait_for_unit("sshd.service") # type: ignore
153
154 node_deployer.succeed("setup-benchmark");
155 node_deployer.succeed("run-benchmark");
156
157 node_deployer.copy_from_vm("run.json")
158 node_deployer.copy_from_vm("stats.json")
159 '';
160 };
161 };
162}
163
164# "${
165# lib.getExe (builtins.getFlake "github:mrshmllow/wire/stable").packages.${system}.wire-small
166# } $wire_args" -n "wire@stable - hive.nix" \
167# "${
168# lib.getExe (builtins.getFlake "github:mrshmllow/wire/stable").packages.${system}.wire-small
169# } $wire_args_flake" -n "wire@stable - flake" \