# What `./swarm-builder-offline.nix` puts on its forge, and the agent it # prebuilds: two deterministic one-commit repos and one toplevel, all built from # `self`. # # hyperhive/hyperhive the source tree of `self` # internal/meta the meta flake of one archetype agent, pinned to the # first repo's commit # # Both commits carry a fixed author and date, so their ids depend on the tree # alone. The meta flake's lock is built from hyperhive's own `flake.lock`, in the # shape `nix flake lock` writes for the pinned flake: every input carries its # `narHash`, so a nix with those source trees in its store needs no fetch for # them. { pkgs, self, forgeUrl, agent, }: let # `hive-meta-flake`'s `render_flake` output for one archetype agent; a unit # test there keeps the file equal to it. metaTemplate = ../../hive-meta-flake/testdata/meta-flake.nix.in; # The same flake, evaluated here with `self` as its `hyperhive` input. toplevel = ((import metaTemplate).outputs { self = null; hyperhive = self; }).nixosConfigurations.${agent}.config.system.build.toplevel; commitEnv = '' export HOME=$TMPDIR export GIT_AUTHOR_NAME=fixture GIT_AUTHOR_EMAIL=fixture@forge.test export GIT_COMMITTER_NAME=fixture GIT_COMMITTER_EMAIL=fixture@forge.test export GIT_AUTHOR_DATE="946684800 +0000" GIT_COMMITTER_DATE="946684800 +0000" ''; hyperhiveRepo = pkgs.runCommand "hyperhive-fixture-repo" { nativeBuildInputs = [ pkgs.git ]; } '' ${commitEnv} cp -a ${self} work chmod -R u+w work git -C work init -q -b main git -C work add -f . git -C work commit -q -m "hyperhive source tree" mkdir $out git clone -q --bare work $out/repo.git git -C work rev-parse HEAD > $out/rev ''; # `nix flake lock`'s result for the template: hyperhive's own nodes next to a # `hyperhive` node pinned by URL and rev, whose follows paths start at the # meta flake's root. lockProgram = pkgs.writeText "meta-lock.jq" '' def from_meta_root: if type == "array" then ["hyperhive"] + . else . end; .nodes.root.inputs as $hyperhiveInputs | { version: 7, root: "root", nodes: ( (.nodes | del(.root) | map_values(if .inputs then .inputs |= map_values(from_meta_root) else . end)) + { hyperhive: { inputs: ($hyperhiveInputs | map_values(from_meta_root)), locked: { lastModified: ($lastModified | tonumber), narHash: $narHash, ref: "refs/heads/main", rev: $rev, revCount: 1, type: "git", url: $url }, original: { rev: $rev, type: "git", url: $url } }, root: { inputs: { hyperhive: "hyperhive", nixpkgs: ["hyperhive", "nixpkgs"] } } } ) } ''; metaRepo = pkgs.runCommand "meta-fixture-repo" { nativeBuildInputs = [ pkgs.git pkgs.jq ]; } '' ${commitEnv} rev=$(cat ${hyperhiveRepo}/rev) url=${forgeUrl}/hyperhive/hyperhive.git mkdir work substitute ${metaTemplate} work/flake.nix --replace-fail @HYPERHIVE_URL@ "git+$url?rev=$rev" jq --arg url "$url" --arg rev "$rev" --arg narHash ${self.narHash} --arg lastModified 946684800 \ -f ${lockProgram} ${self}/flake.lock > work/flake.lock git -C work init -q -b main git -C work add . git -C work commit -q -m "meta flake" mkdir $out git clone -q --bare work $out/repo.git git -C work rev-parse HEAD > $out/rev ''; in { inherit toplevel hyperhiveRepo metaRepo; }