Skip to content

feat(nix): container-aware CLI — auto-route hermes chat into managed container - #27089

Closed
Master-Rensei wants to merge 1 commit into
NousResearch:mainfrom
Master-Rensei:feat/container-aware-cli
Closed

feat(nix): container-aware CLI — auto-route hermes chat into managed container#27089
Master-Rensei wants to merge 1 commit into
NousResearch:mainfrom
Master-Rensei:feat/container-aware-cli

Conversation

@Master-Rensei

Copy link
Copy Markdown

Summary

When container.enable = true in the NixOS module, running hermes chat on the host now automatically execs into the managed container via docker/podman exec. The interactive CLI runs in the same environment as the gateway service — with access to all container-installed packages and tools.

Previously, users had to manually run:

sudo podman exec -it hermes-agent sh -lc '/data/current-package/bin/hermes chat'

Now they just run:

hermes chat

How it works

  1. NixOS activation script writes a .container-mode metadata file to HERMES_HOME containing backend, container_name, and hermes_bin. File is removed when container mode is disabled.

  2. Host CLI detection (hermes_cli/config.py):

    • _is_inside_container() — detects /.dockerenv, /run/.containerenv, and cgroup markers to prevent infinite exec loops
    • get_container_exec_info() — reads .container-mode, returns None if already inside a container or file doesn't exist
  3. Container exec (hermes_cli/main.py):

    • _exec_in_container() validates the container runtime exists and is running, then os.execvp() replaces the process
    • cmd_chat intercepts before normal flow to check for container routing

Safety & fallback

  • --host flag bypasses container routing
  • Falls back to host CLI if: container runtime not found, container not running, inspect fails, or any detection error
  • Already-inside-container detection prevents infinite exec loops
  • --host is stripped from forwarded args (not meaningful inside container)

Files changed

File Change
hermes_cli/config.py _is_inside_container(), get_container_exec_info()
hermes_cli/main.py _exec_in_container(), --host flag, cmd_chat intercept
nix/nixosModules.nix Write/remove .container-mode in activation script
tests/hermes_cli/test_container_aware_cli.py 14 tests
website/docs/getting-started/nix-setup.md Container-aware CLI docs

Test plan

  • 14 unit tests pass (detection, metadata parsing, exec building, fallbacks)
  • Manual test on NixOS with container.enable = true + addToSystemPackages = true
  • Verify --host bypasses container routing
  • Verify fallback when container is stopped

Closes #7380


Reopens closed PR #7470 (by @alt-glitch) from fork Master-Rensei/hermes-agent

…container

When container.enable = true in the NixOS module, running 'hermes chat'
on the host now automatically execs into the managed container via
docker/podman exec. This means the interactive CLI runs in the same
environment as the gateway service, with access to all container-installed
packages and tools.

Implementation:
- NixOS activation script writes .container-mode metadata file to
  HERMES_HOME with backend, container_name, and hermes_bin path
- File is removed when container mode is disabled (nixos-rebuild switch)
- hermes_cli/config.py: _is_inside_container() detects Docker/Podman
  indicators (/.dockerenv, /run/.containerenv, cgroup)
- hermes_cli/config.py: get_container_exec_info() reads .container-mode
  metadata, returns None when already inside a container
- hermes_cli/main.py: _exec_in_container() validates the container is
  running, then os.execvp() replaces the process with the container exec
- cmd_chat intercepts before normal flow, checks container info, execs

Safety:
- --host flag bypasses container routing (run on host regardless)
- Falls back to host CLI if: container runtime not found, container not
  running, inspect fails, or any detection error
- Strips --host from forwarded args (not meaningful inside container)
- Already-inside-container detection prevents infinite exec loops

Closes #7380
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have area/nix Nix flake, NixOS module, container packaging comp/cli CLI entry point, hermes_cli/, setup wizard labels May 16, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #7543 (already merged). This PR reopens a previously closed fork branch, but the feature (container-aware CLI) was already landed via a salvage PR.

@Master-Rensei Master-Rensei closed this by deleting the head repository May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/nix Nix flake, NixOS module, container packaging comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add a container-aware interactive CLI for NixOS managed container mode

2 participants