aboutsummaryrefslogtreecommitdiffstats
path: root/modules/darwin
diff options
context:
space:
mode:
Diffstat (limited to 'modules/darwin')
-rw-r--r--modules/darwin/default.nix7
-rw-r--r--modules/darwin/herdr-caffeinate.nix62
2 files changed, 66 insertions, 3 deletions
diff --git a/modules/darwin/default.nix b/modules/darwin/default.nix
index 26201a1..b4b81a8 100644
--- a/modules/darwin/default.nix
+++ b/modules/darwin/default.nix
@@ -4,6 +4,7 @@
imports = [
./homebrew.nix
./macos.nix
+ ./herdr-caffeinate.nix
];
# Nix is managed by Determinate installer
@@ -41,6 +42,7 @@
# Editors and terminal multiplexers
neovim
tmux
+ herdr
# Shells and shell utilities
zsh
@@ -74,7 +76,6 @@
rustup
# JavaScript runtimes and package managers
- bun
pnpm
deno
@@ -98,7 +99,8 @@
protoc-gen-go-grpc
# Cloud and IaC tools
- pulumi
+ # pulumi-bin over pulumi: the source-built package lags upstream by months
+ pulumi-bin
pulumictl
kubectl
kubernetes-helm
@@ -107,7 +109,6 @@
flyctl
talosctl
tektoncd-cli
- runpodctl
# Task runners and automation
act
diff --git a/modules/darwin/herdr-caffeinate.nix b/modules/darwin/herdr-caffeinate.nix
new file mode 100644
index 0000000..fb23589
--- /dev/null
+++ b/modules/darwin/herdr-caffeinate.nix
@@ -0,0 +1,62 @@
+{ pkgs, ... }:
+
+# Keep the Mac awake while a herdr agent is actively working.
+# A launchd user agent polls `herdr agent list` and holds a `caffeinate`
+# process for as long as at least one agent reports the `working` status.
+let
+ interval = 20;
+
+ supervisor = pkgs.writeShellScript "herdr-caffeinate" ''
+ set -u
+
+ herdr=${pkgs.herdr}/bin/herdr
+ jq=${pkgs.jq}/bin/jq
+ caffeinate=/usr/bin/caffeinate
+
+ caff_pid=""
+
+ stop_caffeinate() {
+ if [ -n "$caff_pid" ] && kill -0 "$caff_pid" 2>/dev/null; then
+ kill "$caff_pid" 2>/dev/null || true
+ fi
+ caff_pid=""
+ }
+
+ trap 'stop_caffeinate; exit 0' TERM INT EXIT
+
+ while true; do
+ working=0
+ # `agent list` fails (nonzero, stderr) when no herdr server is running;
+ # that safely resolves to "no agents working".
+ if list=$("$herdr" agent list 2>/dev/null); then
+ count=$(printf '%s' "$list" \
+ | "$jq" -r '[.result.agents[]? | select(.agent_status == "working")] | length' 2>/dev/null \
+ || printf '0')
+ [ "''${count:-0}" -gt 0 ] && working=1
+ fi
+
+ if [ "$working" -eq 1 ]; then
+ if [ -z "$caff_pid" ] || ! kill -0 "$caff_pid" 2>/dev/null; then
+ # -s prevents system sleep (AC), -i prevents idle sleep (also on battery)
+ "$caffeinate" -s -i &
+ caff_pid=$!
+ fi
+ else
+ stop_caffeinate
+ fi
+
+ sleep ${toString interval}
+ done
+ '';
+in
+{
+ launchd.user.agents.herdr-caffeinate = {
+ serviceConfig = {
+ ProgramArguments = [ "${supervisor}" ];
+ RunAtLoad = true;
+ KeepAlive = true;
+ ProcessType = "Background";
+ StandardErrorPath = "/tmp/herdr-caffeinate.err.log";
+ };
+ };
+}