initial commit
This commit is contained in:
commit
4014d5e658
30 changed files with 911 additions and 0 deletions
62
modules/zmotd.nix
Normal file
62
modules/zmotd.nix
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
{ 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;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue