{ description = "Hermes, confined to act only as one toybox guest: a systemd unit on Linux, the same unit in a microVM on macOS"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; microvm = { url = "github:microvm-nix/microvm.nix"; inputs.nixpkgs.follows = "nixpkgs"; }; # its own nixpkgs: its fixed-output hashes (pnpm deps) are for its pnpm hermes-agent.url = "github:NousResearch/hermes-agent"; }; outputs = { self, nixpkgs, microvm, hermes-agent, }: let inherit (nixpkgs) lib; in { nixosModules = { # the unit that ports; whoever imports it serves its two sockets hermes-guest = { imports = [ hermes-agent.nixosModules.default ./nix/hermes-guest.nix ]; }; # a Linux host: the unit, and the inference proxy, under the host's systemd linux-host = { imports = [ self.nixosModules.hermes-guest ./nix/linux-host.nix ]; }; # the macOS VM's NixOS: the unit, with its sockets relayed over vsock vfkit-vm = { imports = [ microvm.nixosModules.microvm self.nixosModules.hermes-guest ./nix/vfkit-vm.nix ]; }; }; lib = { /** The macOS VM and its launchd agents, for one person's settings. hostDir: where the VM's state image and host sockets live. The toybox socket, hostDir/toybox.sock, is toybox's to serve. */ mkDarwin = { hostDir, model, upstream, keyFile, reasoningEffort ? null, system ? "aarch64-darwin", }: let hostPkgs = nixpkgs.legacyPackages.${system}; vm = lib.nixosSystem { system = lib.replaceString "-darwin" "-linux" system; modules = [ self.nixosModules.vfkit-vm { microvm.vmHostPackages = hostPkgs; services.hermes-guest = { enable = true; inherit model reasoningEffort; vm.hostDir = hostDir; }; } ]; }; runner = vm.config.microvm.declaredRunner; in { inherit vm runner; host = import ./nix/darwin-host.nix { pkgs = hostPkgs; inherit lib runner hostDir upstream keyFile ; }; }; }; packages = lib.genAttrs [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ] ( system: let pkgs = nixpkgs.legacyPackages.${system}; in { # what test/demo.py puts on PATH for Hermes and its checks, and # nothing else: the tools a guest's shell has, from the store, as # the confined unit's closure gives them demo-tools = pkgs.buildEnv { name = "hermes-guest-demo-tools"; paths = [ (pkgs.python3.withPackages (ps: [ ps.pip ])) pkgs.nodejs pkgs.socat pkgs.bash pkgs.coreutils pkgs.findutils pkgs.gnugrep pkgs.gnused pkgs.gnutar pkgs.gzip pkgs.unzip ]; }; } ); formatter = lib.genAttrs [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ] ( system: nixpkgs.legacyPackages.${system}.nixfmt ); }; }