aboutsummaryrefslogtreecommitdiffstats
path: root/modules/vhack/sy/system-info
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-07-30 14:05:39 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-07-30 14:05:39 +0200
commitc153a351659e4596acfc31f00bf594343cbfcd68 (patch)
treea9ed83de07711d6424fbea09aad28891bae5bfe4 /modules/vhack/sy/system-info
parenthosts/server3: Setup prometheus server in agent mode (diff)
downloadnixos-server-c153a351659e4596acfc31f00bf594343cbfcd68.zip
modules: Use namespaces
That might make it easier in the future to merge different server configs together (and thusly facilitate code-reuse.).
Diffstat (limited to 'modules/vhack/sy/system-info')
-rw-r--r--modules/vhack/sy/system-info/module.nix81
1 files changed, 81 insertions, 0 deletions
diff --git a/modules/vhack/sy/system-info/module.nix b/modules/vhack/sy/system-info/module.nix
new file mode 100644
index 0000000..e25e88c
--- /dev/null
+++ b/modules/vhack/sy/system-info/module.nix
@@ -0,0 +1,81 @@
+{
+ lib,
+ config,
+ pkgs,
+ ...
+}: let
+ mkVirtualHostDisplay = name: value: let
+ aliases =
+ if value.serverAliases != []
+ then
+ ": "
+ + builtins.concatStringsSep " " value.serverAliases
+ else "";
+ in ''
+ ${name}${aliases}
+ '';
+ vHosts = builtins.concatStringsSep "" (builtins.attrValues (builtins.mapAttrs mkVirtualHostDisplay config.services.nginx.virtualHosts));
+
+ mkOpenPortDisplay = mode: port: let
+ checkEnabled = service: name:
+ if config.vhack.${service}.enable
+ then name
+ else "<port is '${name}' but service 'vhack.${service}' is not enabled.>";
+ mappings = {
+ "22" = checkEnabled "openssh" "ssh";
+ "80" = checkEnabled "nginx" "http";
+ "443" = checkEnabled "nginx" "https";
+
+ "53" = checkEnabled "dns" "dns";
+
+ "24" = checkEnabled "mail" "mail-lmtp";
+ "465" = checkEnabled "mail" "mail-smtp-tls";
+ "25" = checkEnabled "mail" "mail-smtp";
+ "993" = checkEnabled "mail" "mail-imap-tls";
+ "995" = checkEnabled "mail" "mail-pop3-tls";
+
+ "10222" = checkEnabled "taskchampion-sync" "taskchampion-sync";
+
+ "64738" = checkEnabled "murmur" "murmur";
+
+ # TODO(@bpeetz): Check which service opens these ports: <2025-01-28>
+ "4190" = "???";
+ "8112" = "???";
+ };
+ in ''
+ ${mode} ${builtins.toString port}: ${
+ if (builtins.hasAttr "${builtins.toString port}" mappings)
+ then mappings.${builtins.toString port}
+ else
+ builtins.throw
+ "'${builtins.toString port}' is still missing from the system info port -> name map. Maybe add it?"
+ }
+ '';
+
+ # TODO(@bpeetz): This should probably also include the allowed TCP/UDP port ranges. <2025-01-28>
+ openTCPPorts = builtins.concatStringsSep "" (builtins.map (mkOpenPortDisplay "TCP") config.networking.firewall.allowedTCPPorts);
+ openUDPPorts = builtins.concatStringsSep "" (builtins.map (mkOpenPortDisplay "UDP") config.networking.firewall.allowedUDPPorts);
+
+ markdown = pkgs.writeText "${config.networking.hostName}-system-info.md" ''
+ ## Virtual Hosts
+ ${vHosts}
+ ## Open ports
+ ${openTCPPorts}
+ ${openUDPPorts}
+ '';
+in {
+ options.vhack.system-info = {
+ markdown = lib.mkOption {
+ type = lib.types.package;
+ description = ''
+ A derivation, that builds a markdown file, showing relevant system
+ information for this host.
+ '';
+ readOnly = true;
+ };
+ };
+
+ config.vhack.system-info = {
+ inherit markdown;
+ };
+}