{ config, lib, pkgs, inputs, system, ... }: let cfg = config.samfelag.modules.ai.diwan; diwanPkg = inputs.diwan.packages.${system}.default; in { options.samfelag.modules.ai.diwan = with lib.types; { enable = lib.mkEnableOption "diwan"; notesDir = lib.mkOption { type = str; description = "Path to the content repo diwan ticks against (DIWAN_NOTES_DIR) — notes, not diwan's own code. Required: no default, since there's no sensible one."; }; cadence = lib.my.mkOpt' str "hourly" "systemd OnCalendar expression controlling how often diwan tick runs."; user = lib.my.mkOpt' str config.user.name "User diwan tick runs as — needs access to notesDir and the pi/herdr environment."; }; config = lib.mkIf cfg.enable { # diwan dispatches `pi` agents via `herdr`; both are real dependencies, # not optional extras a host could forget to turn on. samfelag.modules.ai.pi.enable = true; samfelag.modules.ai.herdr.enable = true; environment.systemPackages = [ diwanPkg ]; systemd.timers.diwan-tick = { description = "Run diwan tick periodically"; wantedBy = [ "timers.target" ]; timerConfig = { OnCalendar = cfg.cadence; Persistent = true; }; }; systemd.services.diwan-tick = { description = "diwan tick"; after = [ "network-online.target" ]; wants = [ "network-online.target" ]; environment = { DIWAN_NOTES_DIR = cfg.notesDir; }; serviceConfig = { Type = "oneshot"; User = cfg.user; WorkingDirectory = cfg.notesDir; ExecStart = "${diwanPkg}/bin/diwan tick"; }; }; }; }