summaryrefslogtreecommitdiff
path: root/modules/motd.nix
blob: b91a23ca7ed4af59f3e7353dbc20973f0be963eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{ pkgs, config, ... }:
let
  banner_script = pkgs.writeShellScript "motd_banner.sh" ''
    echo "This is a nice banner, property of wilkuu (wilkuu.xyz)"
    echo -e "\n\tTODO: Put a banner here\t\n"
    echo "Current hostname: ${config.networking.hostName}"
  '';

  # Code stolen from the nix store so I can finish motd_shell
  motdConf =
    pkgs.runCommand "motd.toml"
      {
        __structuredAttrs = true;
        inherit (config.programs.rust-motd) order settings;
        nativeBuildInputs = [
          pkgs.remarshal
          pkgs.jq
        ];
      }
      ''
        cat "$NIX_ATTRS_JSON_FILE" \
          | jq '.settings as $settings
                | .order
                | map({ key: ., value: $settings."\(.)" })
                | from_entries' -r \
          | json2toml /dev/stdin "$out"
      '';

  motd_shell = pkgs.writeShellScriptBin "motd_shell" ''
    if [[ -n "$SHOW_MOTD" && -x /run/current-system/sw/bin/rust-motd ]]; then
      unset SHOW_MOTD
      ${pkgs.rust-motd}/bin/rust-motd ${motdConf}
    fi
    $1
  '';

  filesystems = {
    "omega-relay" = {
      root = "/";
    };
    "apocalypse" = {
      root = "/";
      store = "/store2";
      ntfs = "/win_games";
    };
    "_default" = {
      root = "/";
    };
  };
  current_fses = filesystems.${config.networking.hostName} or filesystems."_default";
in
{
  environment.systemPackages = with pkgs; [
    rust-motd
    motd_shell
  ];
  programs.rust-motd = {
    enable = true;
    order = [
      "banner"
      "uptime"
      "load_avg"
      "filesystems"
      "memory"
      "last_run"
      "global"
    ];
    settings = {
      banner = {
        color = "light_magenta";
        # TODO: Make this nice
        command = "bash ${banner_script}";
      };
      uptime = {
        prefix = "Uptime: ";
      };
      load_avg = {
        format = ''
          Load: [1m] [5m] [15m]
                {one:.02} , {five:.02} , {fifteen:.02}
        '';
      };
      filesystems = current_fses;
      memory = {
        swap_pos = "beside";
      };
      last_run = { };
    };
  };
  security.pam.services.kitty = {
    showMotd = true;
  };
  security.pam.services.kitty-wrapper = {
    showMotd = true;
  };
  security.pam.services.login = {
    showMotd = true;
  };

}