Skip to content

Commit bdd7dfb

Browse files
Generate a set of automatic tools
* pull tools that can describe themselves to the AI
1 parent 9c3a74d commit bdd7dfb

File tree

15 files changed

+574
-101
lines changed

15 files changed

+574
-101
lines changed

functions/hub/Dockerfile.template

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
# syntax = docker/dockerfile:1.4
3+
FROM nixos/nix:2.21.1@sha256:3f6c77ee4d2c82e472e64e6cd7087241dc391421a0b42c22e6849c586d5398d9 AS builder
4+
5+
WORKDIR /tmp/build
6+
RUN mkdir /tmp/nix-store-closure
7+
8+
# ignore SC2046 because the output of nix-store -qR will never have spaces - this is safe here
9+
# hadolint ignore=SC2046
10+
RUN --mount=type=cache,target=/nix,from=nixos/nix:2.21.1,source=/nix \
11+
--mount=type=cache,target=/root/.cache \
12+
--mount=type=bind,target=/tmp/build \
13+
<<EOF
14+
nix \
15+
--extra-experimental-features "nix-command flakes" \
16+
--option filter-syscalls false \
17+
--extra-trusted-substituters "https://cache.iog.io" \
18+
--extra-trusted-public-keys "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" \
19+
--show-trace \
20+
--log-format raw \
21+
build . --out-link /tmp/output/result
22+
cp -R $(nix-store -qR /tmp/output/result) /tmp/nix-store-closure
23+
EOF
24+
25+
FROM babashka/babashka:latest@sha256:9e0381fc4c78ee6ff12fd8836352cf343afba289aceb77e36129d92f30a92cc7
26+
27+
WORKDIR /app
28+
29+
COPY --from=builder /tmp/nix-store-closure /nix/store
30+
COPY --from=builder /tmp/output/ /app/
31+
32+
ENTRYPOINT ["/app/result/bin/entrypoint"]
33+
CMD ["--help"]

functions/hub/flake.lock.template

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"nodes": {
3+
"flake-utils": {
4+
"inputs": {
5+
"systems": "systems"
6+
},
7+
"locked": {
8+
"lastModified": 1710146030,
9+
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
10+
"owner": "numtide",
11+
"repo": "flake-utils",
12+
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
13+
"type": "github"
14+
},
15+
"original": {
16+
"owner": "numtide",
17+
"repo": "flake-utils",
18+
"type": "github"
19+
}
20+
},
21+
"nixpkgs": {
22+
"locked": {
23+
"lastModified": 1718447546,
24+
"narHash": "sha256-JHuXsrC9pr4kA4n7LuuPfWFJUVlDBVJ1TXDVpHEuUgM=",
25+
"owner": "NixOS",
26+
"repo": "nixpkgs",
27+
"rev": "842253bf992c3a7157b67600c2857193f126563a",
28+
"type": "github"
29+
},
30+
"original": {
31+
"owner": "NixOS",
32+
"ref": "nixos-23.11",
33+
"repo": "nixpkgs",
34+
"type": "github"
35+
}
36+
},
37+
"root": {
38+
"inputs": {
39+
"flake-utils": "flake-utils",
40+
"nixpkgs": "nixpkgs"
41+
}
42+
},
43+
"systems": {
44+
"locked": {
45+
"lastModified": 1681028828,
46+
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
47+
"owner": "nix-systems",
48+
"repo": "default",
49+
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
50+
"type": "github"
51+
},
52+
"original": {
53+
"owner": "nix-systems",
54+
"repo": "default",
55+
"type": "github"
56+
}
57+
}
58+
},
59+
"root": "root",
60+
"version": 7
61+
}

functions/hub/flake.nix.template

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
description = "{{tool}}";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils, ...}@inputs:
10+
11+
flake-utils.lib.eachDefaultSystem
12+
(system:
13+
let
14+
pkgs = import nixpkgs {
15+
inherit system;
16+
};
17+
18+
in rec
19+
{
20+
packages = rec {
21+
22+
# this derivation just contains the init.clj script
23+
scripts = pkgs.stdenv.mkDerivation {
24+
name = "scripts";
25+
src = ./.;
26+
installPhase = ''
27+
cp init.clj $out
28+
'';
29+
};
30+
31+
run-entrypoint = pkgs.writeShellScriptBin "entrypoint" ''
32+
export PATH=${pkgs.lib.makeBinPath [pkgs.{{tool}} pkgs.man]}
33+
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
34+
/usr/local/bin/bb ${scripts} "$@"
35+
'';
36+
37+
default = pkgs.buildEnv {
38+
name = "{{tool}}";
39+
paths = [ run-entrypoint ];
40+
};
41+
};
42+
});
43+
}
44+

functions/hub/init.clj.template

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
(ns init
2+
(:require
3+
[babashka.process]
4+
[cheshire.core]))
5+
6+
(defn output [args]
7+
(try
8+
(->
9+
(apply babashka.process/process
10+
{:out :string}
11+
args)
12+
(deref)
13+
(babashka.process/check))
14+
(catch Throwable _ nil)))
15+
16+
(defn man [t]
17+
(output ["man" t]))
18+
(defn help [t]
19+
(output [t "--help"]))
20+
(defn h [t]
21+
(output [t "-h"]))
22+
23+
(try
24+
(let [[json-string & extra-args] *command-line-args*
25+
{:keys [args]} (cheshire.core/parse-string json-string true)]
26+
(println
27+
(-> (if (= "man" (first extra-args))
28+
(let [t "{{tool}}"] (or (man t) (help t) (h t)))
29+
(-> (babashka.process/process
30+
{:out :string}
31+
(format "{{tool}} %s" args))
32+
(deref)
33+
(babashka.process/check)))
34+
(deref)
35+
(babashka.process/check)
36+
:out)))
37+
(catch Throwable t
38+
(binding [*out* *err*]
39+
(println (str "Error: " (.getMessage t)))
40+
(System/exit 1))))
41+
42+

0 commit comments

Comments
 (0)