From 83e6c8c140c9b0036cf4ee0bd62ee3a23cbb24ae Mon Sep 17 00:00:00 2001 From: marc Date: Mon, 9 Nov 2026 11:15:32 +0100 Subject: [PATCH] add diwan module: packages + scheduled tick via systemd timer New modules/ai/diwan.nix: pulls in the diwan flake's package, requires ai.pi and ai.herdr (diwan's real runtime dependencies, not optional extras), and exposes notesDir (DIWAN_NOTES_DIR, required) / cadence (systemd OnCalendar, default hourly) / user (default the host's primary user) as options, wiring a systemd.timer + oneshot systemd.service that runs 'diwan tick'. diwan.url is a temporary path: input (see the flake.nix TODO) -- switch to a real git remote before deploying to any host that isn't this one. Verified via nix eval against an extended thingvellir config: pi/herdr get force-enabled, cadence flows through to OnCalendar, notesDir flows through to the service environment and WorkingDirectory, ExecStart resolves to the real built diwan package. --- flake.lock | 35 +++++++++++++++++++++++++++ flake.nix | 9 +++++++ modules/ai/diwan.nix | 57 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 modules/ai/diwan.nix diff --git a/flake.lock b/flake.lock index 3cac47b..4a06fbd 100644 --- a/flake.lock +++ b/flake.lock @@ -36,6 +36,23 @@ "type": "github" } }, + "diwan": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1794219210, + "narHash": "sha256-dv8srfP1/ZMcql+Da8U9dK/zEsTmW3ViBID7BoTnIVw=", + "path": "/home/marc/projects/diwan", + "type": "path" + }, + "original": { + "path": "/home/marc/projects/diwan", + "type": "path" + } + }, "emacs-overlay": { "inputs": { "nixpkgs": "nixpkgs", @@ -224,6 +241,22 @@ "type": "github" } }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1793977579, + "narHash": "sha256-WrSODdZFVIs/Hh2NzC0bY+ROByi0bATg8WfePX8dPj8=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "4fe25e12eb9f4c744966dd3de5a05246cf098601", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs_2": { "locked": { "lastModified": 1779911860, @@ -326,12 +359,14 @@ "root": { "inputs": { "agenix": "agenix", + "diwan": "diwan", "emacs-overlay": "emacs-overlay", "herdr": "herdr", "home-manager": "home-manager", "hyprcursor-rose-pine": "hyprcursor-rose-pine", "nix-colors": "nix-colors", "nixpkgs": "nixpkgs_4", + "nixpkgs-unstable": "nixpkgs-unstable", "nur": "nur", "zen-browser": "zen-browser" } diff --git a/flake.nix b/flake.nix index d5e190a..5c8d428 100644 --- a/flake.nix +++ b/flake.nix @@ -5,6 +5,7 @@ # - Nixpkgs ---------------------------------- nixpkgs.url = "github:nixos/nixpkgs/nixos-26.05"; + nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable"; # - Home Manager ----------------------------- home-manager.url = "github:nix-community/home-manager/release-26.05"; @@ -43,6 +44,14 @@ # - Herdr ------------------------------------- herdr.url = "github:herdrdev/herdr"; + # - Diwan ------------------------------------- + # TODO: switch to a real git remote (e.g. git.samfelag.xyz) once diwan + # is pushed there -- a local path: input only resolves on whatever + # machine evaluates this flake, which breaks on hosts (like thingvellir) + # that clone and build samfelag themselves. + diwan.url = "path:/home/marc/projects/diwan"; + diwan.inputs.nixpkgs.follows = "nixpkgs"; + }; outputs = inputs @ { self, nixpkgs, home-manager, ... }: diff --git a/modules/ai/diwan.nix b/modules/ai/diwan.nix new file mode 100644 index 0000000..85857c2 --- /dev/null +++ b/modules/ai/diwan.nix @@ -0,0 +1,57 @@ +{ 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"; + }; + }; + }; +}