goose knows about nix
This commit is contained in:
1 parent
25fcf85855
commit
25f648d606
8 files changed
+35
-11
No files matched your search
@@ -34,7 +34,8 @@ const (
|
||||
systemdMgr = "org.freedesktop.systemd1.Manager"
|
||||
sigPoweroff = 38 // SIGRTMIN+4, what `machinectl poweroff` sends
|
||||
|
||||
agentEnvInside = "/var/lib/slackerbot/agent.env"
|
||||
agentEnvInside = "/var/lib/slackerbot/agent.env"
|
||||
nixDaemonSocket = "/nix/var/nix/daemon-socket"
|
||||
)
|
||||
|
||||
type Local struct {
|
||||
@@ -212,6 +213,9 @@ func (l *Local) Start(ctx context.Context, spec node.StartSpec) error {
|
||||
f.Close()
|
||||
}
|
||||
|
||||
if _, err := os.Stat(nixDaemonSocket); err != nil {
|
||||
return fmt.Errorf("containers build through the host's nix-daemon, but %s is missing: %w", nixDaemonSocket, err)
|
||||
}
|
||||
envFile, err := l.writeEnvFile(spec)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -234,9 +238,12 @@ func (l *Local) Start(ctx context.Context, spec node.StartSpec) error {
|
||||
"--directory=" + root,
|
||||
"--keep-unit",
|
||||
"--network-veth", // own network, so every container can use port 1984
|
||||
"--bind-ro=/nix/store",
|
||||
"--bind-ro=" + envFile + ":" + agentEnvInside,
|
||||
"--bind=" + home + ":/root",
|
||||
// Container root is an unprivileged host uid, so the host nix-daemon treats it as untrusted.
|
||||
"--private-users=pick",
|
||||
"--bind-ro=/nix/store:/nix/store:idmap",
|
||||
"--bind-ro=" + nixDaemonSocket,
|
||||
"--bind-ro=" + envFile + ":" + agentEnvInside + ":idmap",
|
||||
"--bind=" + home + ":/root:idmap",
|
||||
}
|
||||
binds := func(list []string, flag string) error {
|
||||
for _, b := range list {
|
||||
|
||||
@@ -24,6 +24,14 @@ const sendFileHelp = "Send a file to the user in Slack: images, videos, PDFs, ar
|
||||
"It's uploaded into the conversation when your turn ends, so mention it in your reply. " +
|
||||
"At most a few files per turn."
|
||||
|
||||
const instructions = `This container runs NixOS with only a few tools installed. Nix is available with flakes, and builds run through the host. Use it for every toolchain and dependency:
|
||||
- For a new project, write a flake.nix with a devShells.default that provides everything the project needs (and packages.default if it builds something), then run commands with ` + "`nix develop -c <command>`" + `.
|
||||
- In an existing project without a flake.nix, add one before installing anything.
|
||||
- Flakes only see files tracked by git, so ` + "`git init`" + ` and ` + "`git add`" + ` new files, including flake.nix and flake.lock, before building.
|
||||
- For a one-off tool, use ` + "`nix shell nixpkgs#<package> -c <command>`" + `.
|
||||
- Don't install things globally (nix-env, nix profile, pip install --user, npm install -g): only the home folder survives a restart.
|
||||
- The host may garbage-collect build outputs, so rebuild instead of relying on old result links.`
|
||||
|
||||
const commandNote = " It's the same as the Slack command `%s`, and runs with the permissions of the person whose message you're answering."
|
||||
|
||||
const (
|
||||
@@ -168,6 +176,7 @@ func (s *Server) handle(m msg) (any, *rpcError) {
|
||||
"protocolVersion": p.ProtocolVersion,
|
||||
"capabilities": map[string]any{"tools": map[string]any{}},
|
||||
"serverInfo": map[string]string{"name": ServerName, "version": "1"},
|
||||
"instructions": instructions,
|
||||
}, nil
|
||||
case "ping":
|
||||
return map[string]any{}, nil
|
||||
|
||||
@@ -29,7 +29,7 @@ func TestSendFileTool(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
lines := strings.Split(strings.TrimSpace(out.String()), "\n")
|
||||
if len(lines) != 5 || !strings.Contains(lines[0], `"protocolVersion":"2025-06-18"`) {
|
||||
if len(lines) != 5 || !strings.Contains(lines[0], `"protocolVersion":"2025-06-18"`) || !strings.Contains(lines[0], "devShells.default") {
|
||||
t.Fatalf("replies: %v", lines)
|
||||
}
|
||||
want := []struct {
|
||||
|
||||
Reference in new issue
Block a user