mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-21 16:18:55 +00:00
* fix(nix): fold makeWrapper line continuations into optionalStrings
When rev == null (any dirty-tree build), the empty optionalString
expansion left the previous line's trailing backslash dangling onto a
blank line, ending the makeWrapper command early and running
`--suffix PYTHONPATH ...` as its own shell command (`--suffix: command
not found`, exit 127). Clean trees passed CI; dirty trees with
extraPythonPackages failed — exactly the path the NixOS module
exercises.
The continuation now lives inside each optionalString (" \\\n --set
..."), so the makeWrapper chain stays intact whether or not the
optional flags expand.
Verified by building with rev = null + extraPythonPackages =
[ pyfiglet ]: wrapper builds, PYTHONPATH suffix lands inside the
makeWrapper call, wrapped `hermes --version` runs, and the collision
check still executes (certifi correctly rejected).
* perf(nix): filter derivation sources to shrink rebuild scope
Every derivation previously saw the whole repo, so any file change
rebuilt everything. Each derivation now gets a filtered src with only
the files it consumes:
- lib.nix: derive npm workspace topology from the root package.json
`workspaces` globs (single source of truth — a new workspace member
is picked up with zero nix edits). pythonSrc (cleanSourceWith)
excludes the JS workspace trees, docs/website, docker/.github,
tests, nix/, flake.nix/flake.lock, root docs, and skills/ +
optional-skills/. importNpmLock reads from a fileset-filtered
npmRoot (root manifests + member package.jsons only).
- mkNpmPassthru takes `dirs` — the workspace dirs the package
contains — and builds a per-package fileset src from them. web and
desktop include apps/shared (file: dep). One shared
`nix run .#update-npm-lockfile` replaces the per-package
update_*_lockfile bins that only existed inside build sandboxes.
- python.nix: release venv loads the uv2nix workspace from pythonSrc.
The editable venv keeps an unfiltered ./.. root —
mkEditablePyprojectOverlay calls lib.path.splitRoot, which rejects
a cleanSourceWith set, and the editable install reads the live
checkout anyway.
- hermes-agent.nix: skills ship exclusively via HERMES_BUNDLED_SKILLS
/ HERMES_OPTIONAL_SKILLS (same mechanism as Homebrew packaging;
setup.py's _data_file_tree returns [] for missing dirs), so
SKILL.md edits no longer rebuild the venv. optional-mcps stays in
the wheel — pyproject.toml lists its manifests as explicit
data-files. Bundled assets are symlinked instead of copied, making
the wrapper drv near-instant when only an input changed.
__pycache__ filtered from bundled skills.
- checks.nix: find -L through the new symlinks; assert
optional-skills presence + HERMES_OPTIONAL_SKILLS in the wrapper.
- run_tests.sh: fall back to $HERMES_PYTHON when no local venv
exists, guarded by an `import pytest` probe (HERMES_PYTHON from a
wrapped hermes binary points at the release venv, which has no
pytest — without the guard every test file dies with "No module
named pytest" while the runner exits 0).
Verified: nix flake check exit 0; built .#default .#tui .#web
.#desktop; SKILL.md and flake.nix edits leave the venv drvPath
unchanged; .py edits leave the tui drvPath unchanged; .tsx edits
leave the venv drvPath unchanged (and do change the tui drv);
scripts/run_tests.sh runs 299 tests green through both the venv and
HERMES_PYTHON paths, and rejects a pytest-less HERMES_PYTHON.
* refactor(nix): overlay aliases the flake's own package instead of re-instantiating
The overlay previously re-called callPackage against the consumer's
nixpkgs (final), so pkgs.hermes-agent could be a different derivation
than nix build .#default and the NixOS module's default — an untested
build matrix against arbitrary consumer nixpkgs versions, for a
package whose Python side is uv2nix-locked anyway.
Now the overlay is a pure alias for the flake's own locked package:
one callPackage site (packages.nix), everything else references it.
.override { ... } still works — callPackage's makeOverridable travels
with the derivation.
Verified: direct drvPath == overlaid drvPath; .override produces a
distinct drv.
* fix(nix): dedupe extraPlugins assertions, replace MESSAGING_CWD with terminal.cwd
- Delete the duplicated extraPlugins duplicate-name assertions block
(same assertion declared twice back to back).
- Stop setting the deprecated MESSAGING_CWD env var, which made the
module trip hermes' own startup deprecation warning. The working
directory is now injected as terminal.cwd into the generated
config.yaml; cfg.settings wins via recursiveUpdate, and container
mode maps to the in-container mount path.
193 lines
6.1 KiB
Nix
193 lines
6.1 KiB
Nix
# nix/desktop.nix — Hermes Desktop (Electron) app build + wrapper
|
|
#
|
|
# `hermesAgent` is the fully-built `.#default` package — it ships the
|
|
# `hermes` binary with the venv, runtime PATH, bundled skills/plugins, etc.
|
|
# already wired up. We point the desktop at it via the existing
|
|
# `HERMES_DESKTOP_HERMES` override env var, so the desktop's resolver
|
|
# uses our fully wrapped binary at step 4 ("existing Hermes CLI").
|
|
# No reimplementation of the agent resolution in this wrapper.
|
|
{
|
|
pkgs,
|
|
lib,
|
|
stdenv,
|
|
makeWrapper,
|
|
hermesNpmLib,
|
|
electron,
|
|
hermesAgent,
|
|
...
|
|
}:
|
|
let
|
|
# apps/shared ships as a file: workspace dep of apps/desktop, so its
|
|
# source must be in the filtered src tree too.
|
|
npm = hermesNpmLib.mkNpmPassthru {
|
|
dirs = [
|
|
"apps/desktop"
|
|
"apps/shared"
|
|
];
|
|
};
|
|
|
|
packageJson = builtins.fromJSON (builtins.readFile (npm.src + "/apps/desktop/package.json"));
|
|
version = packageJson.version;
|
|
|
|
electronHeaders = pkgs.fetchurl {
|
|
url = "https://artifacts.electronjs.org/headers/dist/v${electron.version}/node-v${electron.version}-headers.tar.gz";
|
|
sha256 = "sha256-zi/QMwRZ0+FwE9XTE+DiSIeJXAwxmLKEaBWD5W3pMOI=";
|
|
};
|
|
|
|
# node-pty ships no Electron-tagged prebuild we can trust to match this
|
|
# exact nixpkgs electron version, so it's always compiled from source
|
|
# against Electron's own headers (not whatever Node ran `npm`).
|
|
targetPlatform =
|
|
if stdenv.hostPlatform.isDarwin then
|
|
"darwin"
|
|
else if stdenv.hostPlatform.isLinux then
|
|
"linux"
|
|
else
|
|
throw "hermes-desktop: unsupported host platform for node-pty staging";
|
|
|
|
targetArch =
|
|
if stdenv.hostPlatform.isAarch64 then
|
|
"arm64"
|
|
else if stdenv.hostPlatform.isx86_64 then
|
|
"x64"
|
|
else
|
|
throw "hermes-desktop: unsupported host arch for node-pty staging";
|
|
|
|
# Build the renderer (dist/ + electron/ + package.json).
|
|
renderer = pkgs.buildNpmPackage (
|
|
npm
|
|
// {
|
|
pname = "hermes-desktop-renderer";
|
|
inherit version;
|
|
doCheck = true;
|
|
|
|
buildPhase = ''
|
|
runHook preBuild
|
|
|
|
mkdir -p apps/desktop/build
|
|
|
|
patchShebangs .
|
|
|
|
pushd apps/desktop
|
|
# typecheck :3
|
|
npm exec tsc -b
|
|
|
|
# build the renderer bundle
|
|
# vite's emptyOutDir wipes dist/ on every run
|
|
# so it has to be first
|
|
npm exec vite build
|
|
|
|
# build the electron bundle
|
|
node scripts/bundle-electron-main.mjs
|
|
|
|
# Compile node-pty against Electron's actual ABI (the nixpkgs
|
|
# `electron` we ship). Headers come from a pinned fetchurl input
|
|
# since the sandbox has no network here, so node-gyp's
|
|
# normal --disturl download path can't run.
|
|
mkdir -p "$TMPDIR/electron-headers"
|
|
tar -xzf ${electronHeaders} -C "$TMPDIR/electron-headers" --strip-components=1
|
|
|
|
npm rebuild node-pty \
|
|
--build-from-source \
|
|
--runtime=electron \
|
|
--target=${electron.version} \
|
|
--nodedir="$TMPDIR/electron-headers" \
|
|
--disturl="" \
|
|
--offline
|
|
|
|
# Target platform/arch come from stdenv.hostPlatform, not the
|
|
# build host's own process.platform/arch.
|
|
node scripts/stage-native-deps.mjs ${targetPlatform} ${targetArch}
|
|
popd
|
|
|
|
runHook postBuild
|
|
'';
|
|
|
|
checkPhase = ''
|
|
runHook preCheck
|
|
|
|
pushd apps/desktop
|
|
|
|
npm run postbuild
|
|
|
|
# validate staged node-pty native binary is present.
|
|
STAGED_PTY_NODE="./dist/node_modules/node-pty/build/Release/pty.node"
|
|
|
|
if [ ! -f "$STAGED_PTY_NODE" ]; then
|
|
echo "FATAL: Missing staged node-pty native binary at $STAGED_PTY_NODE"
|
|
echo "node-pty must be compiled natively"
|
|
exit 1
|
|
fi
|
|
|
|
popd
|
|
|
|
runHook postCheck
|
|
'';
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
mkdir -p $out
|
|
# vite writes to apps/desktop/dist/ (we cd'd there in buildPhase).
|
|
# stage-native-deps.mjs stages node-pty into dist/node_modules/node-pty,
|
|
# so copying dist/ wholesale carries the native dep along with the
|
|
# esbuild bundle that require()s it. apps/desktop/build was created
|
|
# before the cd.
|
|
cp -rn apps/desktop/dist $out/
|
|
|
|
echo '{"schemaVersion":1,"commit":"nix-dummy-commit","branch":"nix","dirty":false,"source":"nix"}' > $out/install-stamp.json
|
|
|
|
cp -n apps/desktop/package.json $out/
|
|
runHook postInstall
|
|
'';
|
|
}
|
|
);
|
|
in
|
|
|
|
# Electron wrapper: nixpkgs' electron binary pointed at the renderer dir.
|
|
stdenv.mkDerivation {
|
|
pname = "hermes-desktop";
|
|
inherit version;
|
|
|
|
dontUnpack = true;
|
|
dontBuild = true;
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
|
|
mkdir -p $out/share/hermes-desktop $out/bin
|
|
cp -r ${renderer}/* $out/share/hermes-desktop/
|
|
|
|
# Standard nixpkgs pattern for electron-builder apps: patch process.resourcesPath
|
|
# to point to the app's directory. In Nix, unpackaged electron defaults this
|
|
# to the electron distribution's resources path, breaking extraResources lookups.
|
|
substituteInPlace $out/share/hermes-desktop/dist/electron-main.mjs \
|
|
--replace-fail "process.resourcesPath" "'$out/share/hermes-desktop'"
|
|
|
|
# Wrap the nixpkgs electron binary to launch our app. Set
|
|
# HERMES_DESKTOP_HERMES to the absolute path of the nix-built `hermes`
|
|
# binary so the desktop's resolver step 4 ("existing Hermes CLI on
|
|
# PATH") uses our fully wrapped binary — venv with all deps,
|
|
# bundled skills/plugins, runtime PATH (ripgrep/git/ffmpeg/etc).
|
|
# No reimplementation of the agent resolver in the wrapper.
|
|
makeWrapper ${lib.getExe electron} $out/bin/hermes-desktop \
|
|
--add-flags "$out/share/hermes-desktop" \
|
|
--set HERMES_DESKTOP_HERMES "${lib.getExe hermesAgent}" \
|
|
--set ELECTRON_IS_DEV 0
|
|
|
|
runHook postInstall
|
|
'';
|
|
|
|
passthru = {
|
|
inherit (renderer.passthru) packageJsonPath;
|
|
};
|
|
|
|
meta = with lib; {
|
|
description = "Native Electron desktop shell for Hermes Agent";
|
|
homepage = "https://github.com/NousResearch/hermes-agent";
|
|
license = licenses.mit;
|
|
platforms = platforms.unix;
|
|
mainProgram = "hermes-desktop";
|
|
};
|
|
}
|