2022-02-13 04:01:22 +00:00
|
|
|
{ lib, pkgs, config, ... }:
|
2022-02-13 13:10:21 +00:00
|
|
|
let
|
|
|
|
inherit (lib) optionalAttrs filterAttrs genAttrs mkIf mkDefault;
|
2022-02-13 17:44:14 +00:00
|
|
|
inherit (lib.my) mkOpt' mkBoolOpt';
|
2022-02-13 04:01:22 +00:00
|
|
|
|
2022-02-13 13:10:21 +00:00
|
|
|
cfg = config.my.dynamic-motd;
|
2022-02-13 04:01:22 +00:00
|
|
|
|
2022-02-13 13:10:21 +00:00
|
|
|
scriptBin = pkgs.writeShellScript "dynamic-motd-script" cfg.script;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.my.dynamic-motd = with lib.types; {
|
2022-02-13 17:44:14 +00:00
|
|
|
enable = mkBoolOpt' true "Whether to enable the dynamic message of the day PAM module.";
|
2022-05-28 13:57:01 +01:00
|
|
|
services = mkOpt' (listOf str) [ "login" "sshd" ] "PAM services to enable the dynamic message of the day module for.";
|
2022-02-13 17:44:14 +00:00
|
|
|
script = mkOpt' (nullOr lines) null "Script that generates message of the day.";
|
2022-02-13 13:10:21 +00:00
|
|
|
};
|
2022-02-13 04:01:22 +00:00
|
|
|
|
2022-02-13 13:10:21 +00:00
|
|
|
config = mkIf (cfg.enable && cfg.script != null) {
|
|
|
|
security.pam.services = genAttrs cfg.services (s: {
|
|
|
|
text = mkDefault
|
|
|
|
''
|
|
|
|
session optional ${pkgs.pam}/lib/security/pam_exec.so stdout quiet ${scriptBin}
|
|
|
|
'';
|
|
|
|
});
|
|
|
|
};
|
2022-02-15 20:50:27 +00:00
|
|
|
|
|
|
|
meta.buildDocsInSandbox = false;
|
2022-02-13 13:10:21 +00:00
|
|
|
}
|