Skip to content

Commit 1fbe77a

Browse files
monyarmMartinNikov
authored andcommitted
feat(machines): add machine per nixos module
1 parent 7b83b03 commit 1fbe77a

16 files changed

+221
-0
lines changed

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
./checks
223223
./modules
224224
./packages
225+
./machines
225226
./shells
226227
];
227228
systems = [

machines/default.nix

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
lib,
3+
self,
4+
...
5+
}:
6+
let
7+
system = "x86_64-linux";
8+
mkMachine = x: {
9+
"${lib.removeSuffix ".nix" x}" = lib.nixosSystem {
10+
specialArgs = { inherit self system; };
11+
modules = lib.unique [
12+
./modules/base.nix
13+
./modules/${x}
14+
];
15+
};
16+
};
17+
in
18+
{
19+
flake.nixosConfigurations = (
20+
lib.mergeAttrsList (lib.map (x: mkMachine x) (builtins.attrNames (builtins.readDir ./modules)))
21+
);
22+
}

machines/modules/all.nix

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
self,
3+
lib,
4+
system,
5+
...
6+
}:
7+
{
8+
imports = lib.map (x: ./. + "/${x}") (
9+
builtins.attrNames (
10+
lib.removeAttrs (builtins.readDir ./.) [
11+
"base.nix"
12+
"all.nix"
13+
]
14+
)
15+
);
16+
17+
environment.systemPackages = lib.attrValues self.packages."${system}";
18+
}

machines/modules/base.nix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{ system, ... }:
2+
{
3+
nixpkgs.system = system;
4+
fileSystems = {
5+
"/".device = "/not/real";
6+
};
7+
boot.loader.grub.devices = [ "/not/real" ];
8+
virtualisation.vmVariant = {
9+
virtualization = {
10+
diskSize = 10 * 1024 * 1024 * 1024; # 10GB
11+
memorySize = 8192; # 8GB
12+
cores = 4;
13+
};
14+
};
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{ self, ... }:
2+
{
3+
imports = [
4+
self.modules.nixos.ethereum-validators-monitoring
5+
];
6+
7+
#TODO: Figure out the arguments for this service and enable it
8+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{ self, ... }:
2+
{
3+
imports = [
4+
self.modules.nixos.folder-size-metrics
5+
];
6+
7+
services.folder-size-metrics = {
8+
enable = true;
9+
# args = { #Unchanged
10+
# port = 8888;
11+
# base-path = "/var/lib";
12+
# interval-sec = 60;
13+
# };
14+
};
15+
}

machines/modules/healthcheck.nix

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{ self, pkgs, ... }:
2+
{
3+
imports = [
4+
self.modules.nixos.healthcheck
5+
];
6+
7+
systemd.services.test = {
8+
description = "";
9+
enable = true;
10+
path = with pkgs; [
11+
];
12+
serviceConfig = {
13+
Type = "oneshot";
14+
Restart = "on-failure";
15+
RestartSec = "10s";
16+
17+
ExecStart = ''
18+
sleep 10; # Simulate a startup delay.
19+
echo "Starting test service...";
20+
echo "Test" > /tmp/test.log
21+
while true ; do
22+
echo "Test" | nc -l 8080
23+
done
24+
'';
25+
};
26+
};
27+
28+
# --- Health Check Configuration ---
29+
mcl.services.test.healthcheck = {
30+
runtimePackages = with pkgs; [
31+
netcat
32+
curl
33+
];
34+
exec = ''
35+
sleep 10; # Simulate a startup delay.
36+
echo "Starting test service...";
37+
echo "Test" > /tmp/test.log
38+
while true ; do
39+
echo "Test" | nc -l 8080
40+
done
41+
'';
42+
43+
# READINESS: Use the notify pattern to signal when the service is truly ready.
44+
readiness-probe = {
45+
enable = true;
46+
command = "ls /tmp/test.log";
47+
interval = 2;
48+
statusWaitingMessage = "Test starting, waiting...";
49+
statusReadyMessage = "Test is ready.";
50+
};
51+
52+
# LIVENESS: After startup, use a timer to periodically check health.
53+
liveness-probe = {
54+
enable = true;
55+
command = "[ \"$(nc -w 2 localhost 8080)\" = \"Test2\" ]";
56+
initialDelay = 15;
57+
interval = 30; # Check every 30 seconds.
58+
timeout = 5;
59+
};
60+
};
61+
}

machines/modules/lido-keys-api.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{ self, ... }:
2+
{
3+
imports = [
4+
self.modules.nixos.lido-keys-api
5+
];
6+
7+
#TODO: Figure out the arguments for this service and enable it
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{ self, ... }:
2+
{
3+
imports = [
4+
self.modules.nixos.lido-validator-ejector
5+
];
6+
7+
#TODO: Figure out the arguments for this service and enable it
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{ self, ... }:
2+
{
3+
imports = [
4+
self.modules.nixos.lido-withdrawals-automation
5+
];
6+
7+
#TODO: Figure out the arguments for this service and enable it
8+
}

0 commit comments

Comments
 (0)