nixfiles/modules/dynamic-motd.nix

26 lines
678 B
Nix
Raw Normal View History

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;
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; {
enable = mkBoolOpt true;
services = mkOpt (listOf str) [ "login" "ssh" ];
script = mkOpt (nullOr lines) null;
};
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}
'';
});
};
}