Skip to content

Commit 4daa7fb

Browse files
georgiyordPetarKirov
authored andcommitted
chore(modules): Get modules up to date with infra repo equivelants
1 parent c390969 commit 4daa7fb

File tree

3 files changed

+113
-33
lines changed

3 files changed

+113
-33
lines changed

modules/commands.nix

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{ withSystem, ... }:
2+
{
3+
flake.modules.nixos.mcl-commands =
4+
{
5+
lib,
6+
pkgs,
7+
flakeArgs,
8+
config,
9+
...
10+
}:
11+
let
12+
cfg = config.programs.admin-cmds;
13+
14+
makeSystemctlCommand =
15+
service: command:
16+
pkgs.writeShellApplication {
17+
name = "${service}-${command}";
18+
text = "systemctl ${command} ${service}.service";
19+
};
20+
systemctlCommands = builtins.concatMap (
21+
service: map (command: (makeSystemctlCommand service command)) cfg.systemctl-commands
22+
) cfg.services;
23+
24+
getPackageCommands =
25+
package:
26+
lib.pipe "${lib.getExe package}/.." [
27+
builtins.readDir
28+
builtins.attrNames
29+
];
30+
31+
server-help = pkgs.writeShellApplication {
32+
name = "server-help";
33+
text = ''
34+
echo -e "There are a few sudo commands which:\n
35+
* Restart certain services\n
36+
* Get certain services status\n
37+
* Get certain services logs\n\n
38+
39+
Available commands:\n
40+
${
41+
lib.pipe systemctlCommands [
42+
(map getPackageCommands)
43+
builtins.concatLists
44+
(builtins.concatStringsSep "\n")
45+
]
46+
}"
47+
'';
48+
};
49+
in
50+
{
51+
options.programs.admin-cmds = with lib; {
52+
services = mkOption {
53+
type = types.listOf types.str;
54+
default = [ ];
55+
example = [
56+
"nginx"
57+
"grafana"
58+
"nimbus-eth2"
59+
];
60+
description = ''
61+
Services for which you have admin commands.
62+
'';
63+
};
64+
65+
systemctl-commands = mkOption {
66+
type = types.listOf types.str;
67+
default = [
68+
"restart"
69+
"status"
70+
"stop"
71+
];
72+
example = [
73+
"restart"
74+
"start"
75+
"stop"
76+
];
77+
description = ''
78+
Systemd commands which you can use for services.
79+
'';
80+
};
81+
};
82+
83+
config = lib.mkIf (cfg.services != [ ]) {
84+
security.sudo.extraRules = [
85+
{
86+
groups = [ "metacraft" ];
87+
commands = [
88+
(lib.pipe systemctlCommands [
89+
(map getPackageCommands)
90+
builtins.concatLists
91+
(lib.concatMapStringsSep ", " (n: "/run/current-system/sw/bin/${n}"))
92+
])
93+
];
94+
}
95+
];
96+
97+
environment.systemPackages = systemctlCommands ++ [ server-help ];
98+
};
99+
};
100+
}

modules/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
./secrets.nix
1111
./mcl-disko
1212
./pharos
13+
./commands.nix
1314
];
1415
}

modules/host-info.nix

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,28 @@
99
{
1010
options.mcl.host-info = with lib; {
1111
type = mkOption {
12-
type = types.nullOr (
13-
types.enum [
14-
"desktop"
15-
"server"
16-
"container"
17-
]
18-
);
19-
default = null;
20-
example = [ "desktop" ];
12+
type = types.enum [
13+
"notebook"
14+
"desktop"
15+
"server"
16+
"container"
17+
];
18+
example = "desktop";
2119
description = ''
2220
Whether this host is a desktop or a server.
2321
'';
2422
};
2523

2624
isDebugVM = mkOption {
27-
type = types.nullOr types.bool;
28-
default = null;
29-
example = [ "false" ];
25+
type = types.bool;
26+
example = false;
3027
description = ''
31-
Whether this configuration is a VM variant with extra debug
32-
functionality.
28+
Whether this configuration is a VM variant with extra debug functionality.
3329
'';
3430
};
3531

3632
configPath = mkOption {
37-
type = types.nullOr types.path;
38-
default = null;
33+
type = types.path;
3934
example = [ "machines/server/solunska-server" ];
4035
description = ''
4136
The configuration path for this host relative to the repo root.
@@ -44,28 +39,12 @@
4439

4540
sshKey = mkOption {
4641
type = types.nullOr types.str;
47-
default = "";
42+
default = null;
4843
example = "ssh-ed25519 AAAAC3Nza";
4944
description = ''
5045
The public ssh key for this host.
5146
'';
5247
};
5348
};
54-
config = {
55-
assertions = [
56-
{
57-
assertion = config.mcl.host-info.type != null;
58-
message = "mcl.host-info.type must be defined for every host";
59-
}
60-
{
61-
assertion = config.mcl.host-info.isDebugVM != null;
62-
message = "mcl.host-info.isDebugVM must be defined for every host";
63-
}
64-
{
65-
assertion = config.mcl.host-info.configPath != null;
66-
message = "mcl.host-info.configPath must be defined for every host";
67-
}
68-
];
69-
};
7049
};
7150
}

0 commit comments

Comments
 (0)