From 4219a91df5e85e1af5e4aa03956093200e015e0c Mon Sep 17 00:00:00 2001 From: Siddharth Balyan <52913345+alt-glitch@users.noreply.github.com> Date: Mon, 8 Jun 2026 20:10:47 +0530 Subject: [PATCH] fix(nix): make config.yaml group-writable under addToSystemPackages (#41940) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit addToSystemPackages exports HERMES_HOME system-wide and puts the hermes CLI on interactive users' PATH, so those users (in the hermes group) share the gateway's state — that's the option's whole purpose. But the activation script wrote config.yaml as 0640 (group read-only), so an interactive user saving a setting via the CLI/TUI hit: error: [Errno 13] Permission denied: '/var/lib/hermes/.hermes/config.yaml' Make the mode conditional: 0660 when addToSystemPackages is set (group hermes can write), else the previous 0640. .env stays 0640 either way — it holds secrets, not user-facing settings. The config merge already preserves user-added keys across rebuilds, so this simply lets interactive hermes-group users actually make those edits. Verified by evaluating the module's activation script for both option values: addToSystemPackages=true -> chmod 0660, false -> chmod 0640. --- nix/nixosModules.nix | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/nix/nixosModules.nix b/nix/nixosModules.nix index 19abc81a3b7..4458926b0f0 100644 --- a/nix/nixosModules.nix +++ b/nix/nixosModules.nix @@ -49,6 +49,12 @@ configMergeScript = pkgs.callPackage ./configMergeScript.nix { }; + # config.yaml mode: group-writable (0660) when interactive users share this + # HERMES_HOME via addToSystemPackages, so they can save settings through the + # CLI/TUI without hitting EACCES; otherwise group-read-only (0640). Secrets + # (.env) stay 0640 regardless — see below. + configYamlMode = if cfg.addToSystemPackages then "0660" else "0640"; + # Generate .env from non-secret environment attrset envFileContent = lib.concatStringsSep "\n" ( lib.mapAttrsToList (k: v: "${k}=${v}") cfg.environment @@ -728,7 +734,8 @@ chmod 0750 ${cfg.stateDir}/home # Create subdirs, set setgid + group-writable, migrate existing files. - # Nix-managed files (config.yaml, .env, .managed) stay 0640/0644. + # Nix-managed .env/.managed stay 0640/0644; config.yaml uses + # configYamlMode (0660 under addToSystemPackages, else 0640). find ${cfg.stateDir}/.hermes -maxdepth 1 \ \( -name "*.db" -o -name "*.db-wal" -o -name "*.db-shm" -o -name "SOUL.md" \) \ -exec chmod g+rw {} + 2>/dev/null || true @@ -743,12 +750,14 @@ # Merge Nix settings into existing config.yaml. # Preserves user-added keys (skills, streaming, etc.); Nix keys win. # If configFile is user-provided (not generated), overwrite instead of merge. + # Mode is configYamlMode (0660 under addToSystemPackages so interactive + # hermes-group users can save settings via the CLI/TUI, else 0640). ${if cfg.configFile != null then '' - install -o ${cfg.user} -g ${cfg.group} -m 0640 -D ${configFile} ${cfg.stateDir}/.hermes/config.yaml + install -o ${cfg.user} -g ${cfg.group} -m ${configYamlMode} -D ${configFile} ${cfg.stateDir}/.hermes/config.yaml '' else '' ${configMergeScript} ${generatedConfigFile} ${cfg.stateDir}/.hermes/config.yaml chown ${cfg.user}:${cfg.group} ${cfg.stateDir}/.hermes/config.yaml - chmod 0640 ${cfg.stateDir}/.hermes/config.yaml + chmod ${configYamlMode} ${cfg.stateDir}/.hermes/config.yaml ''} # Managed mode marker (so interactive shells also detect NixOS management)