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.
This commit is contained in:
marc committed 2026-11-09 11:24:43 +01:00
1 parent 7c58561dc5
commit 83e6c8c140
3 files changed
+101

No files matched your search

Generated
+35
View File
@@ -36,6 +36,23 @@
"type": "github" "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": { "emacs-overlay": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
@@ -224,6 +241,22 @@
"type": "github" "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": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1779911860, "lastModified": 1779911860,
@@ -326,12 +359,14 @@
"root": { "root": {
"inputs": { "inputs": {
"agenix": "agenix", "agenix": "agenix",
"diwan": "diwan",
"emacs-overlay": "emacs-overlay", "emacs-overlay": "emacs-overlay",
"herdr": "herdr", "herdr": "herdr",
"home-manager": "home-manager", "home-manager": "home-manager",
"hyprcursor-rose-pine": "hyprcursor-rose-pine", "hyprcursor-rose-pine": "hyprcursor-rose-pine",
"nix-colors": "nix-colors", "nix-colors": "nix-colors",
"nixpkgs": "nixpkgs_4", "nixpkgs": "nixpkgs_4",
"nixpkgs-unstable": "nixpkgs-unstable",
"nur": "nur", "nur": "nur",
"zen-browser": "zen-browser" "zen-browser": "zen-browser"
} }
+9
View File
@@ -5,6 +5,7 @@
# - Nixpkgs ---------------------------------- # - Nixpkgs ----------------------------------
nixpkgs.url = "github:nixos/nixpkgs/nixos-26.05"; nixpkgs.url = "github:nixos/nixpkgs/nixos-26.05";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
# - Home Manager ----------------------------- # - Home Manager -----------------------------
home-manager.url = "github:nix-community/home-manager/release-26.05"; home-manager.url = "github:nix-community/home-manager/release-26.05";
@@ -43,6 +44,14 @@
# - Herdr ------------------------------------- # - Herdr -------------------------------------
herdr.url = "github:herdrdev/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, ... }: outputs = inputs @ { self, nixpkgs, home-manager, ... }:
+57
View File
@@ -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";
};
};
};
}