about summary refs log tree commit diff
path: root/nixos/modules/security
diff options
context:
space:
mode:
authorMarkus Napierkowski <markus.napierkowski@cyberus-technology.de>2022-11-11 16:11:37 +0100
committerMarkus Napierkowski <markus.napierkowski@cyberus-technology.de>2022-12-15 11:54:26 +0100
commit192ae663cc6b50832a5546f294fd4db6f37bf712 (patch)
tree92965fa669e0d01cd0c13f26f7588daa933a0adc /nixos/modules/security
parent7634c3250b6870e76f2e611cb95b72392add9aef (diff)
nixos/pam: allow backing the motd with a file
Diffstat (limited to 'nixos/modules/security')
-rw-r--r--nixos/modules/security/pam.nix20
1 files changed, 18 insertions, 2 deletions
diff --git a/nixos/modules/security/pam.nix b/nixos/modules/security/pam.nix
index 21e1749d85032..08b51788e0828 100644
--- a/nixos/modules/security/pam.nix
+++ b/nixos/modules/security/pam.nix
@@ -694,7 +694,7 @@ let
           optionalString (cfg.limits != []) ''
             session required ${pkgs.pam}/lib/security/pam_limits.so conf=${makeLimitsConf cfg.limits}
           '' +
-          optionalString (cfg.showMotd && config.users.motd != null) ''
+          optionalString (cfg.showMotd && (config.users.motd != null || config.users.motdFile != null)) ''
             session optional ${pkgs.pam}/lib/security/pam_motd.so motd=${motd}
           '' +
           optionalString (cfg.enableAppArmor && config.security.apparmor.enable) ''
@@ -775,7 +775,9 @@ let
     };
   }));
 
-  motd = pkgs.writeText "motd" config.users.motd;
+  motd = if isNull config.users.motdFile
+         then pkgs.writeText "motd" config.users.motd
+         else config.users.motdFile;
 
   makePAMService = name: service:
     { name = "pam.d/${name}";
@@ -1199,12 +1201,26 @@ in
       description = lib.mdDoc "Message of the day shown to users when they log in.";
     };
 
+    users.motdFile = mkOption {
+      default = null;
+      example = "/etc/motd";
+      type = types.nullOr types.path;
+      description = lib.mdDoc "A file containing the message of the day shown to users when they log in.";
+    };
   };
 
 
   ###### implementation
 
   config = {
+    assertions = [
+      {
+        assertion = isNull config.users.motd || isNull config.users.motdFile;
+        message = ''
+          Only one of users.motd and users.motdFile can be set.
+        '';
+      }
+    ];
 
     environment.systemPackages =
       # Include the PAM modules in the system path mostly for the manpages.