pvv-nixos-config/misc/rust-motd.nix

87 lines
2.3 KiB
Nix
Raw Permalink Normal View History

2021-12-15 18:15:03 +01:00
{ pkgs, lib, config, ... }:
{
environment = {
systemPackages = with pkgs; [
rust-motd
toilet
];
loginShellInit = let
motd = "${pkgs.rust-motd}/bin/rust-motd /etc/${config.environment.etc.rustMotdConfig.target}";
in ''
# Assure stdout is a terminal, so headless programs won't be broken
if [ "x''${SSH_TTY}" != "x" ]; then
${motd}
fi
'';
etc.rustMotdConfig = {
target = "rust-motd-config.toml";
source = let
cfg = {
global = {
progress_full_character = "=";
progress_empty_character = "=";
progress_prefix = "[";
progress_suffix = "]";
time_format = "%Y-%m-%d %H:%M:%S";
};
banner = {
color = "red";
command = "hostname | ${pkgs.toilet}/bin/toilet -f mono9";
};
2024-08-04 02:30:25 +02:00
2021-12-15 18:15:03 +01:00
service_status = {
Accounts = "accounts-daemon";
Cron = "cron";
Docker = "docker";
Matrix = "matrix-synapse";
sshd = "sshd";
};
2024-08-04 02:30:25 +02:00
2021-12-15 18:15:03 +01:00
uptime = {
prefix = "Uptime: ";
};
2024-08-04 02:30:25 +02:00
2021-12-15 18:15:03 +01:00
# Not relevant for server
# user_service_status = {
# Gpg-agent = "gpg-agent";
# };
2024-08-04 02:30:25 +02:00
2021-12-15 18:15:03 +01:00
filesystems = let
inherit (lib.attrsets) attrNames listToAttrs nameValuePair;
inherit (lib.lists) imap1;
inherit (config) fileSystems;
imap1Attrs' = f: set:
listToAttrs (imap1 (i: attr: f i attr set.${attr}) (attrNames set));
getName = i: v: if (v.label != null) then v.label else "<? ${toString i}>";
in
imap1Attrs' (i: n: v: nameValuePair (getName i v) n) fileSystems;
2024-08-04 02:30:25 +02:00
2021-12-15 18:15:03 +01:00
memory = {
swap_pos = "beside"; # or "below" or "none"
};
last_login = let
inherit (lib.lists) imap1;
inherit (lib.attrsets) filterAttrs nameValuePair attrValues listToAttrs;
inherit (config.users) users;
2024-08-04 02:30:25 +02:00
2021-12-15 18:15:03 +01:00
normalUsers = filterAttrs (n: v: v.isNormalUser || n == "root") users;
userNPVs = imap1 (index: user: nameValuePair user.name index) (attrValues normalUsers);
in listToAttrs userNPVs;
last_run = {};
};
2024-08-04 02:30:25 +02:00
2021-12-15 18:15:03 +01:00
toml = pkgs.formats.toml {};
in toml.generate "rust-motd.toml" cfg;
};
};
}