haccfiles/modules/buildinfo.nix
stuebinm d20acbfe58 monit: a couple new checks
move the monit config out of mail.nix, and add two checks:
 - has any systemd unit failed?
 - is the currently deployed commit the tip of the main branch of
   haccfiles?
2024-04-07 16:30:57 +02:00

33 lines
1 KiB
Nix

{ config, lib, pkgs, sources, ... }:
let
self = sources.self;
slice = string: start: length: with lib;
strings.concatStrings
(lists.take length
(lists.drop start
(strings.stringToCharacters string)));
formatDate = date:
let
year = slice date 0 4;
month = slice date 4 2;
day = slice date 6 2;
hour = slice date 8 2;
minute = slice date 10 2;
second = slice date 12 2;
in
"${year}-${month}-${day} ${hour}:${minute}:${second} UTC";
in
{
system.nixos.label = "${config.system.nixos.release}-haccfiles-${self.shortRev or self.dirtyShortRev}";
users.motd = ''
Welcome to ${config.networking.hostName}, running NixOS ${config.system.nixos.release}!
Built from haccfiles ${self.rev or self.dirtyRev}.
Last commit was at ${formatDate self.lastModifiedDate}.
${if self ? dirtyRev then "\nPlease remember to commit your changes.\n" else ""}
'';
# used by monit
environment.etc."haccfiles-commit".text = self.rev or self.dirtyRev;
}