diff --git a/devshell/commands.nix b/devshell/commands.nix index 6bc944c..3110a4c 100644 --- a/devshell/commands.nix +++ b/devshell/commands.nix @@ -35,6 +35,27 @@ in help = "Remove home-manager flake.nix link"; command = "rm -f ${homeFlake}"; } + { + name = "slop"; + category = "utilities"; + help = "Ask slop-broker for privileged operations (`slop guide`); uses `.keys/slop-request.key` if present"; + # Built from this checkout, so it matches the branch. Without a key it uses `SLOP_BROKER`, + # `~/.config/slop/config.toml` or vsock, as the installed client does. + command = '' + key="$PRJ_ROOT/.keys/slop-request.key" + if [ -z "''${SLOP_BROKER-}" ] && [ -f "$key" ]; then + export SLOP_BROKER=ssh:slop@palace.h.nul.ie + export SLOP_SSH="ssh -i $key -o IdentitiesOnly=yes -o IdentityAgent=none" + fi + exec ${pkgs.slop-broker}/bin/slop "$@" + ''; + } + { + name = "slop-approve"; + category = "utilities"; + help = "Answer slop-broker requests; its key stays outside the checkout, where agents can't read it"; + command = ''exec ${pkgs.slop-broker}/bin/slop-approve "$@"''; + } { name = "ragenix"; category = "utilities"; diff --git a/docs/README.md b/docs/README.md index 8aeebc0..2d21caa 100644 --- a/docs/README.md +++ b/docs/README.md @@ -94,6 +94,7 @@ The laptop is indexed in [`mobile/README.md`](mobile/README.md). ## Misc - [`misc/installer.md`](misc/installer.md) — the custom NixOS installer image. +- [`slop-broker.md`](slop-broker.md) — how these boxes use `slop-broker`, the agents' approval broker. ## A note on the assignment tables diff --git a/docs/sites/colony/shill/containers/middleman.md b/docs/sites/colony/shill/containers/middleman.md index 0b7673c..b25b0b0 100644 --- a/docs/sites/colony/shill/containers/middleman.md +++ b/docs/sites/colony/shill/containers/middleman.md @@ -42,8 +42,8 @@ username/password provider. Its cookie domain is `.nul.ie`; gated vhosts include [Pocket ID](https://pocket-id.org) (`services.pocket-id`) is a passkey-only OpenID Connect provider at `id.nul.ie`, for apps that sign in with OIDC (first the `slop-broker` approvals web -app). It is meant to replace nginx-sso's Google sign-in later, with oauth2-proxy in front of apps -that lack OIDC. +app, see [`slop-broker.md`](../../../../slop-broker.md)). It is meant to replace nginx-sso's +Google sign-in later, with oauth2-proxy in front of apps that lack OIDC. - Listens on `127.0.0.1:1411` behind nginx and keeps its SQLite database in `/var/lib/pocket-id` (persisted by `my.tmproot`). The `middleman/pocket-id-encryption-key` secret encrypts it. diff --git a/docs/slop-broker.md b/docs/slop-broker.md new file mode 100644 index 0000000..5fde071 --- /dev/null +++ b/docs/slop-broker.md @@ -0,0 +1,25 @@ +# slop-broker + +[`slop-broker`](https://git.nul.ie/dev/slop-broker) carries out privileged operations (SSH +commands, deploys, builds, and later secrets, DNS and previews) for the coding agents on +[`slop-cannon`](sites/home/slop-cannon.md) and other boxes, under a policy and usually after Dev +approves each one. Agents use the `slop` CLI. + +The broker, its NixOS and home-manager modules, its design and the agents' guide live in its own +repository, which this flake takes as the `slop-broker` input. This page covers how these boxes use +it; for how it works, read the repository's +[design](https://git.nul.ie/dev/slop-broker/src/branch/main/docs/design.md). + +## In this flake + +- **Input:** `slop-broker` in [`flake.nix`](../flake.nix). Its overlay provides `pkgs.slop-broker`, + and the common modules import `services.slop-broker`, `services.slop-broker-builder`, + `services.slop-broker-cache` and `programs.slop`. Update it with `nix flake update slop-broker`. +- **Persistence:** [`tmproot.nix`](../nixos/modules/tmproot.nix) keeps `/var/lib/slop-broker` and + the builder's home when those services are enabled. +- **Agents:** `my.agents.slop` (in the shared `agents` home-manager module) installs `slop` and adds + the guide (`share/slop-broker/slop-tools.md`) as a Claude rule (`~/.claude/rules/slop.md`) and + as Codex's `AGENTS.md`. +- **Devshell:** `slop` and `slop-approve`, built from the locked input. `slop` uses + `.keys/slop-request.key` over SSH when that file exists; an approver key never goes in `.keys/`, + because agents can read the checkout. diff --git a/flake.lock b/flake.lock index 93df53d..5598c30 100644 --- a/flake.lock +++ b/flake.lock @@ -1196,7 +1196,8 @@ "openwrt-feeds": "openwrt-feeds", "openwrt-imagebuilder": "openwrt-imagebuilder", "paseo": "paseo", - "ragenix": "ragenix" + "ragenix": "ragenix", + "slop-broker": "slop-broker" } }, "rust-overlay": { @@ -1241,6 +1242,27 @@ "type": "github" } }, + "slop-broker": { + "inputs": { + "nixpkgs": [ + "nixpkgs-unstable" + ] + }, + "locked": { + "lastModified": 1795563488, + "narHash": "sha256-fTRKZn95BBANQpEGkhrmHSoPb9yTl59ZfvfzVbXeo5g=", + "ref": "main", + "rev": "21c2d4715ec3bcf4a90b41c16125db75c599b8b7", + "revCount": 26, + "type": "git", + "url": "https://git.nul.ie/dev/slop-broker" + }, + "original": { + "ref": "main", + "type": "git", + "url": "https://git.nul.ie/dev/slop-broker" + } + }, "systems": { "locked": { "lastModified": 1681028828, diff --git a/flake.nix b/flake.nix index 848638d..cf5ca02 100644 --- a/flake.nix +++ b/flake.nix @@ -77,6 +77,8 @@ # Pinned to a release. Don't make it follow our nixpkgs: its npm dependency hash is tied to its # own nixpkgs pin. paseo.url = "github:getpaseo/paseo/v0.15.4"; + slop-broker.url = "git+https://git.nul.ie/dev/slop-broker?ref=main"; + slop-broker.inputs.nixpkgs.follows = "nixpkgs-unstable"; borgthin.url = "github:devplayer0/borg"; # TODO: Update borgthin so this works # borgthin.inputs.nixpkgs.follows = "nixpkgs-mine"; @@ -167,6 +169,7 @@ myPkgsOverlay determinateOverlay + inputs.slop-broker.overlays.default inputs.devshell.overlays.default inputs.ragenix.overlays.default inputs.deploy-rs.overlays.default @@ -183,6 +186,7 @@ myPkgsOverlay determinateOverlay + inputs.slop-broker.overlays.default ]; config = { diff --git a/home-manager/modules/agents/default.nix b/home-manager/modules/agents/default.nix index 83c2fce..39ba3ba 100644 --- a/home-manager/modules/agents/default.nix +++ b/home-manager/modules/agents/default.nix @@ -1,17 +1,21 @@ { lib, pkgs, inputs, config, options, ... }: let - inherit (lib) mkIf optionalAttrs; + inherit (lib) mkIf optional optionalAttrs; inherit (lib.my) mkBoolOpt'; cfg = config.my.agents; agentPkgs = inputs.llm-agents.packages.${pkgs.stdenv.hostPlatform.system}; + slopGuide = "${pkgs.slop-broker}/share/slop-broker/slop-tools.md"; in { options.my.agents = { enable = mkBoolOpt' false "Whether to install and configure coding agents (Claude Code, Codex)."; + slop.enable = mkBoolOpt' false "Whether agents use the `slop` client for privileged operations."; }; config = mkIf cfg.enable { + home.packages = optional cfg.slop.enable pkgs.slop-broker; + programs = { # TODO: Remove mutableSettings guard when Home Manager 26.11 releases; 26.05 lacks it. codex = { @@ -34,11 +38,16 @@ in }; } // optionalAttrs (options.programs.codex ? mutableSettings) { mutableSettings = true; + } // optionalAttrs cfg.slop.enable { + context = slopGuide; }; claude-code = { enable = true; package = agentPkgs.claude-code; + rules = optionalAttrs cfg.slop.enable { + slop = slopGuide; + }; settings = { model = "opus"; theme = "auto"; diff --git a/home-manager/modules/common.nix b/home-manager/modules/common.nix index dcd8129..e234885 100644 --- a/home-manager/modules/common.nix +++ b/home-manager/modules/common.nix @@ -12,6 +12,7 @@ in { # Disabled: breaks `nix flake check` in CI (see flake.nix pi-agent note). # imports = [ inputs.pi-agent.homeModules.default ]; + imports = [ inputs.slop-broker.homeModules.slop ]; options = with lib.types; { my = { diff --git a/nixos/modules/common.nix b/nixos/modules/common.nix index 838124b..a0dd9a7 100644 --- a/nixos/modules/common.nix +++ b/nixos/modules/common.nix @@ -17,6 +17,7 @@ in inputs.harmonia.nixosModules.harmonia inputs.bootvine.nixosModules.default inputs.paseo.nixosModules.paseo + inputs.slop-broker.nixosModules.default ]; config = mkMerge [ diff --git a/nixos/modules/tmproot.nix b/nixos/modules/tmproot.nix index 1cce5f5..0e2e11a 100644 --- a/nixos/modules/tmproot.nix +++ b/nixos/modules/tmproot.nix @@ -479,6 +479,26 @@ in }) (persistSimpleSvc "headscale") (persistSimpleSvc "pocket-id") + (mkIf config.services.slop-broker.enable { + my.tmproot.persistence.config.directories = [ + { + directory = "/var/lib/slop-broker"; + user = "slop-broker"; + group = "slop-broker"; + mode = "0700"; + } + ]; + }) + (mkIf config.services.slop-broker-builder.enable { + my.tmproot.persistence.config.directories = [ + { + directory = "/var/lib/slop-broker-build"; + user = "slop-broker-build"; + group = "slop-broker-build"; + mode = "0700"; + } + ]; + }) (mkIf config.services.tailscale.enable { my.tmproot.persistence.config.directories = [ "/var/lib/tailscale" ]; })