flake-config/modules/zmotd.nix
2025-11-09 23:51:40 -05:00

62 lines
1.7 KiB
Nix

{ lib, pkgs, config, ... }:
{
options.services.zmotd = {
enable = lib.mkEnableOption "zmotd";
interval = lib.mkOption {
default = "5m";
example = "5m";
description = "Change the timing of zmotd runs.";
type = lib.types.str;
};
config = lib.mkOption {
default = {
entries = [
{ m = "hostname"; f = "fig"; }
{ m = "distro"; }
{ m = "kernel"; }
{ m = "load"; }
{ m = "uptime"; }
];
};
type = lib.types.attrsOf lib.types.anything;
};
motdFile = lib.mkOption {
default = "/etc/motd";
description = "Change the where zmotd outputs to.";
};
};
config = lib.mkIf config.services.zmotd.enable {
users.motdFile = config.services.zmotd.motdFile;
systemd.services.zmotd = {
description = "Generate dynamic MOTD using zmotd";
enable = config.services.zmotd.enable;
serviceConfig = {
Type = "oneshot";
User = "root";
Group = "root";
ExecStart = let
motdFile = config.services.zmotd.motdFile;
configFile = pkgs.writers.writeTOML
"zmotd-config.toml"
config.services.zmotd.config;
in pkgs.writeShellScript "zmotd-wrapper" ''
${pkgs.zmotd}/bin/zmotd ${configFile} > ${motdFile}
'';
};
};
systemd.timers.zmotd = {
description = "Regenerate MOTD often";
enable = config.services.zmotd.enable;
wantedBy = [ "timers.target" ];
timerConfig = {
OnActiveSec = "0s";
OnUnitActiveSec = config.services.zmotd.interval;
Unit = "zmotd.service";
Persistent = true;
};
};
};
}