Skip to content

Commit 3cae945

Browse files
committed
chore(modules): Get modules up to date with infra repo equivelants
1 parent c390969 commit 3cae945

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
type = mkOption {
1212
type = types.nullOr (
1313
types.enum [
14+
"notebook"
1415
"desktop"
1516
"server"
1617
"container"
@@ -43,7 +44,7 @@
4344
};
4445

4546
sshKey = mkOption {
46-
type = types.nullOr types.str;
47+
type = types.str;
4748
default = "";
4849
example = "ssh-ed25519 AAAAC3Nza";
4950
description = ''

0 commit comments

Comments
 (0)