Files
slop-broker/nix/modules/nixos/builder.nix
T
jackos1998andClaude Opus 5.5 005e3d32df ops: Add age secrets
`slop secret keys|set|generate|rekey|read` work with an agenix secret
in the requester's checkout: it sends the ciphertext, and the broker
decrypts it with its own age identity and returns new ciphertext.
Field edits work on env and JSON secrets.

The path and recipients are the requester's, so before approval the
builder reads the protected main branch: it looks the ciphertext's
blob up there, so approvers see which file it really is, and
evaluates that branch's rules file to compare the recipients.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 00:56:17 +00:00

61 lines
2.4 KiB
Nix

# The builder (`services.slop-broker-builder`): a user without keys that evaluates and builds
# commits for the broker, which reaches it over SSH with a forced command.
{ lib, pkgs, config, ... }:
let
inherit (lib) mkIf hasPrefix;
mkOpt' = type: default: description: lib.mkOption { inherit type default description; };
mkBoolOpt' = default: description: mkOpt' lib.types.bool default description;
cfg = config.services.slop-broker-builder;
user = "slop-broker-build";
home = "/var/lib/${user}";
builderConfig = (pkgs.formats.toml { }).generate "slop-broker-builder.toml" {
inherit (cfg) repository branch;
key = cfg.keyFile;
directory = home;
path = map (p: "${p}/bin") [ pkgs.git config.nix.package pkgs.openssh pkgs.coreutils ];
};
in
{
options.services.slop-broker-builder = with lib.types; {
enable = mkBoolOpt' false "Whether to build commits for `slop-broker` deploys, as `${user}`.";
package = lib.mkOption {
type = package;
default = pkgs.slop-broker;
defaultText = lib.literalExpression "pkgs.slop-broker";
description = "slop-broker package; the flake's modules default to its own.";
};
repository = mkOpt' str "" "Git repository to fetch commits from.";
branch = mkOpt' str "master"
"Branch that approvals list commits relative to, and that secrets are checked against; only people should be able to push to it.";
keyFile = mkOpt' str "" "Runtime path to a read-only key for `repository`, readable by the builder.";
brokerKeys = mkOpt' (listOf str) [ ] "SSH public keys of brokers that may run builds.";
};
config = mkIf cfg.enable {
assertions = [
{
assertion = cfg.repository != "" && hasPrefix "/" cfg.keyFile && !(hasPrefix "/nix/store/" cfg.keyFile);
message = "slop-broker builder needs a repository and a runtime key file.";
}
];
# Evaluates and builds agent-written commits, so it holds nothing but a read-only Git key.
# Brokers' keys can only run one build per connection.
users = {
groups.${user} = { };
users.${user} = {
isSystemUser = true;
group = user;
inherit home;
createHome = true;
shell = pkgs.bashInteractive;
openssh.authorizedKeys.keys = map
(k: ''restrict,command="${cfg.package}/bin/slop-broker builder --config ${builderConfig}" ${k}'')
cfg.brokerKeys;
};
};
};
}