-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake-module.nix
75 lines (65 loc) · 1.94 KB
/
flake-module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{ self, inputs, ... }:
{
imports = [ ];
perSystem =
{
pkgs,
self',
lib,
system,
...
}:
with lib;
let
scriptExec = pkgs.callPackage ./pkgs/script-exec { };
in
{
apps.healthchecks = {
type = "app";
program =
let
nixosConfigurationsToVerify = filterAttrs (
machine: configuration: builtins.hasAttr "healthchecks" configuration.options
) self.nixosConfigurations;
useEmoji = true;
rawCommands =
nixosConfiguration:
let
commandOptions = nixosConfiguration.options.healthchecks.rawCommands.value;
commandScripts = mapAttrsToList (
group: groupConfiguration:
(mapAttrsToList (
topic:
{ title, script }:
''
${scriptExec}/bin/script-exec --title "${title}" ${optionalString useEmoji "--emoji"} --time ${script}
''
) groupConfiguration)
) commandOptions;
in
flatten commandScripts;
verify =
machineName: nixosConfiguration:
let
machineHeader =
if useEmoji then
''
echo ""
echo "🖥️ ${machineName}"
''
else
''
echo ""
echo "{Machine} ${machineName}"
'';
in
''
${machineHeader}
${concatStringsSep "\n" (rawCommands nixosConfiguration)}
'';
allCommands = concatStringsSep "\n\n" (mapAttrsToList verify nixosConfigurationsToVerify);
in
pkgs.writers.writeBashBin "verify" allCommands;
};
};
}