swarm: set an agent's config repo avatar from its icon
The agent module exposes the PNG nix renders from the agent's icon as the read-only option services.hyperhive.agent.iconPng, which the forge and matrix avatar syncs now share. When the builder reads an icon it builds that one attribute with nix build and sends the file, base64, next to the SVG in the meta build reply, so the builder runs no renderer of its own. After recording the icon, the controller sets the avatar of agent-configs/<agent> from the PNG as the forge admin, removes the avatar when the icon is removed, and leaves it alone when the builder sent no PNG. A marker per repo holds the image's fingerprint, so a build whose icon did not change makes no forge call; a forge that refuses the avatar does not fail the build. An old builder sends no PNG, so it changes nothing.
This commit is contained in:
parent
8a0615ccfc
commit
1a31a4cd5a
4 changed files with 499 additions and 25 deletions
|
|
@ -149,6 +149,25 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
options.services.hyperhive.agent.iconPng = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.package;
|
||||
readOnly = true;
|
||||
default =
|
||||
if config.services.hyperhive.agent.icon == null then
|
||||
null
|
||||
else
|
||||
pkgs.runCommand "hive-agent-icon.png" { nativeBuildInputs = [ pkgs.librsvg ]; } ''
|
||||
rsvg-convert -f png -w 512 -h 512 ${config.services.hyperhive.agent.icon} -o $out
|
||||
'';
|
||||
defaultText = lib.literalMD "`icon` rasterized to a 512×512 PNG, or `null` when no icon is set";
|
||||
description = ''
|
||||
`icon` rasterized to a 512×512 PNG at build time: the image the agent
|
||||
uploads as its forge and matrix avatar, and the one the swarm builder
|
||||
builds and sends to the controller, which sets it as the avatar of the
|
||||
agent's config repo. Read-only; `null` when no icon is set.
|
||||
'';
|
||||
};
|
||||
|
||||
config = {
|
||||
assertions = [
|
||||
# Guard the inputs-routed-as-output pattern: the agent flake.nix is
|
||||
|
|
|
|||
|
|
@ -21,13 +21,11 @@ let
|
|||
if [ -s "$f" ] && [ -r "$f" ]; then TOKEN_FILE="$f"; break; fi
|
||||
done
|
||||
'';
|
||||
# Same 512×512 rasterization of the agent icon the matrix avatar
|
||||
# sync uses (./matrix.nix — identical derivation, same store path).
|
||||
# Only forced when an icon is configured AND a forge is (the avatar-sync
|
||||
# unit below, the one thing that references this, is gated on both).
|
||||
iconPng = pkgs.runCommand "hive-agent-icon.png" { nativeBuildInputs = [ pkgs.librsvg ]; } ''
|
||||
rsvg-convert -f png -w 512 -h 512 ${config.services.hyperhive.agent.icon} -o $out
|
||||
'';
|
||||
# The 512×512 rasterization of the agent icon (`services.hyperhive.agent.iconPng`,
|
||||
# declared in ./default.nix and shared with the matrix avatar sync and the
|
||||
# swarm builder). Only forced when an icon is configured AND a forge is (the
|
||||
# avatar-sync unit below, the one thing that references this, is gated on both).
|
||||
iconPng = config.services.hyperhive.agent.iconPng;
|
||||
|
||||
# git credential helper for the hive forge --- the exact shape
|
||||
# `./github.nix` uses for github.com, for the same two reasons: the token
|
||||
|
|
|
|||
|
|
@ -46,9 +46,7 @@ let
|
|||
# Only forced when an icon is configured — the `HIVE_ICON_PNG` daemon-env
|
||||
# entry is gated on `services.hyperhive.agent.icon != null`, so this binding stays lazy
|
||||
# when no icon is set.
|
||||
iconPng = pkgs.runCommand "hive-agent-icon.png" { nativeBuildInputs = [ pkgs.librsvg ]; } ''
|
||||
rsvg-convert -f png -w 512 -h 512 ${config.services.hyperhive.agent.icon} -o $out
|
||||
'';
|
||||
iconPng = config.services.hyperhive.agent.iconPng;
|
||||
in
|
||||
{
|
||||
options.services.hyperhive.agent.matrix.url = lib.mkOption {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,17 @@ let
|
|||
# SVG: the icon is only ever a gate here, and nothing this case reads
|
||||
# rasterizes it.
|
||||
agentIconNoForge = agentWith { services.hyperhive.agent.icon = pkgs.emptyFile; };
|
||||
agentNoIcon = agentWith { };
|
||||
cases = [
|
||||
{
|
||||
# The builder builds this option and sends the PNG to the controller for
|
||||
# the config repo's avatar, so it must be a derivation when an icon is set
|
||||
# and null when none is (the builder skips the build then).
|
||||
name = "iconPng is the rasterized icon, and null without one";
|
||||
ok =
|
||||
lib.isDerivation agentIconNoForge.services.hyperhive.agent.iconPng
|
||||
&& agentNoIcon.services.hyperhive.agent.iconPng == null;
|
||||
}
|
||||
{
|
||||
# The absence class, and a gate asymmetry nothing else can see. A `.path`
|
||||
# unit is `wantedBy = multi-user.target` and names a `Unit=` by
|
||||
|
|
|
|||
Loading…
Reference in a new issue