diff --git a/system/default.nix b/system/default.nix index c5aedc3..d440db3 100644 --- a/system/default.nix +++ b/system/default.nix @@ -4,6 +4,7 @@ ./acme.nix ./autoupgrade.nix ./monitoring + ./motd.nix ./packages.nix ./nix.nix ./root-user.nix diff --git a/system/motd.nix b/system/motd.nix new file mode 100644 index 0000000..29e7cd1 --- /dev/null +++ b/system/motd.nix @@ -0,0 +1,28 @@ +{ config, lib, self, ... }: + +let + hostname = config.networking.hostName; + domain = config.networking.domain or ""; + fqdn = if domain != "" then "${hostname}.${domain}" else hostname; + + # Get commit hash (handles both clean and dirty trees) + shortRev = self.shortRev or self.dirtyShortRev or "unknown"; + + # Format timestamp from lastModified (Unix timestamp) + # lastModifiedDate is in format "YYYYMMDDHHMMSS" + dateStr = self.sourceInfo.lastModifiedDate or "unknown"; + formattedDate = if dateStr != "unknown" then + "${builtins.substring 0 4 dateStr}-${builtins.substring 4 2 dateStr}-${builtins.substring 6 2 dateStr} ${builtins.substring 8 2 dateStr}:${builtins.substring 10 2 dateStr}" + else + "unknown"; + + banner = '' + #################################### + ${fqdn} + Commit: ${shortRev} (${formattedDate}) + #################################### + ''; +in +{ + users.motd = lib.mkDefault banner; +}