Radish alpha
r
rad:z254T5p17bdFPmzfDojsdjo4HjpoZ
Radicle Infrastructure as Code (NixOS, OpenTofu, …)
Radicle
Git
os/mixin/radicle-stats: Collect `rad stats`
Lorenz Leutgeb committed 9 months ago
commit 50df86e20c4495657551ea40340962513db238a8
parent 94e1a77
4 files changed +46 -1
modified os/host/iris/radicle.nix
@@ -8,6 +8,7 @@ in {
  imports = [
    ../../mixin/radicle.nix
    ../../mixin/radicle-permissive.nix
+
    ../../mixin/radicle-stats.nix
  ];

  fileSystems."/var/lib/radicle" = {
modified os/host/rosa/radicle.nix
@@ -8,6 +8,7 @@ in {
  imports = [
    ../../mixin/radicle.nix
    ../../mixin/radicle-permissive.nix
+
    ../../mixin/radicle-stats.nix
  ];

  fileSystems."/var/lib/radicle" = {
modified os/host/seed/radicle.nix
@@ -3,7 +3,10 @@
  pkgs,
  ...
}: {
-
  imports = [../../mixin/radicle.nix];
+
  imports = [
+
    ../../mixin/radicle.nix
+
    ../../mixin/radicle-stats.nix
+
  ];

  fileSystems."/var/lib/radicle" = {
    device = "/dev/disk/by-id/scsi-0HC_Volume_30473554";
added os/mixin/radicle-stats.nix
@@ -0,0 +1,40 @@
+
{
+
  config,
+
  pkgs,
+
  lib,
+
  ...
+
}: let
+
  name = "radicle-stats";
+
in {
+
  systemd = {
+
    timers.${name} = {
+
      wantedBy = ["timers.target"];
+
      timerConfig = {
+
        OnBootSec = "1m";
+
        OnUnitActiveSec = "6h";
+
        Unit = "${name}.service";
+
      };
+
    };
+
    services = {
+
      ${name} = let
+
        cmd = "rad-system";
+
        rad =
+
          lib.findFirst (x: x.name == cmd) (throw "could not find `${cmd}`") config.environment.systemPackages;
+
      in {
+
        script = ''
+
          set -xeu
+
          mkdir -p /tmp/radicle
+
          ${lib.getExe rad} stats | ${lib.getExe pkgs.jq} --compact-output '. * { timestamp: now | strftime("%s") }' >> /tmp/radicle/stats.jsonl
+
        '';
+
        serviceConfig = {
+
          Type = "oneshot";
+
          User = "root";
+
        };
+
      };
+
      nginx.serviceConfig.BindReadOnlyPaths = [
+
        "/tmp/radicle/stats.jsonl:/tmp/radicle/stats.jsonl"
+
      ];
+
    };
+
  };
+
  services.nginx.virtualHosts.${config.networking.fqdn}.locations."/tmp/".alias = "/tmp/radicle/";
+
}