Skip to content

Commit c2b06de

Browse files
committed
refactor(modules): Add host-info as nixosModules
1 parent 991561d commit c2b06de

File tree

2 files changed

+58
-45
lines changed

2 files changed

+58
-45
lines changed

modules/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
./pyroscope
77
./folder-size-metrics
88
./shard-split
9+
./host-info.nix
910
];
1011
}

modules/host-info.nix

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,62 @@
1-
{
2-
config,
3-
lib,
4-
...
5-
}: {
6-
options.mcl.host-info = with lib; {
7-
type = mkOption {
8-
type = types.nullOr (types.enum ["desktop" "server"]);
9-
default = null;
10-
example = ["desktop"];
11-
description = ''
12-
Whether this host is a desktop or a server.
13-
'';
14-
};
1+
{withSystem, ...}: {
2+
flake.nixosModules.mcl-host-info = {
3+
config,
4+
lib,
5+
...
6+
}: {
7+
options.mcl.host-info = with lib; {
8+
type = mkOption {
9+
type = types.nullOr (types.enum ["desktop" "server" "container"]);
10+
default = null;
11+
example = ["desktop"];
12+
description = ''
13+
Whether this host is a desktop or a server.
14+
'';
15+
};
1516

16-
isVM = mkOption {
17-
type = types.nullOr types.bool;
18-
default = null;
19-
example = ["false"];
20-
description = ''
21-
Whether this configuration is a VM variant.
22-
'';
23-
};
17+
isDebugVM = mkOption {
18+
type = types.nullOr types.bool;
19+
default = null;
20+
example = ["false"];
21+
description = ''
22+
Whether this configuration is a VM variant with extra debug
23+
functionality.
24+
'';
25+
};
26+
27+
configPath = mkOption {
28+
type = types.nullOr types.path;
29+
default = null;
30+
example = ["machines/server/solunska-server"];
31+
description = ''
32+
The configuration path for this host relative to the repo root.
33+
'';
34+
};
2435

25-
configPath = mkOption {
26-
type = types.nullOr types.string;
27-
default = null;
28-
example = ["machines/server/solunska-server"];
29-
description = ''
30-
The configuration path for this host relative to the repo root.
31-
'';
36+
sshKey = mkOption {
37+
type = types.nullOr types.str;
38+
default = "";
39+
example = "ssh-ed25519 AAAAC3Nza";
40+
description = ''
41+
The public ssh key for this host.
42+
'';
43+
};
44+
};
45+
config = {
46+
assertions = [
47+
{
48+
assertion = config.mcl.host-info.type != null;
49+
message = "mcl.host-info.type must be defined for every host";
50+
}
51+
{
52+
assertion = config.mcl.host-info.isDebugVM != null;
53+
message = "mcl.host-info.isDebugVM must be defined for every host";
54+
}
55+
{
56+
assertion = config.mcl.host-info.configPath != null;
57+
message = "mcl.host-info.configPath must be defined for every host";
58+
}
59+
];
3260
};
33-
};
34-
config = {
35-
assertions = [
36-
{
37-
assertion = config.mcl.host-info.type != null;
38-
message = "mcl.host-info.type must be defined for every host";
39-
}
40-
{
41-
assertion = config.mcl.host-info.isVM != null;
42-
message = "mcl.host-info.isVM must be defined for every host";
43-
}
44-
{
45-
assertion = config.mcl.host-info.configPath != null;
46-
message = "mcl.host-info.configPath must be defined for every host";
47-
}
48-
];
4961
};
5062
}

0 commit comments

Comments
 (0)