Skip to content

The agent that grows with you

feat(nix): pass the token as HERMES_DASHBOARD_SESSION_TOKEN=file:<path>

ethernetc90b27e8e3a2
diff --git a/nix/checks.nix b/nix/checks.nix
index 3f01aa3f8a2..90329865fc9 100644
--- a/nix/checks.nix
+++ b/nix/checks.nix
@@ -505,11 +505,12 @@ json.dump(sorted(leaf_paths(DEFAULT_CONFIG)), sys.stdout, indent=2)
# list (systemd) or an EnvironmentVariables set (launchd).
backendTokenText =
# Same NAME=value shape on both platforms, so one assertion
- # covers each: systemd renders an Environment list, launchd an
- # attribute set that holds the bare value.
+ # covers each: systemd renders an Environment list (with the
+ # value quoted), launchd an attribute set that holds the bare
+ # value.
if pkgs.stdenv.hostPlatform.isDarwin then
- "HERMES_DASHBOARD_SESSION_TOKEN_FILE="
- + (cfg.launchd.agents.hermes-backend.config.EnvironmentVariables.HERMES_DASHBOARD_SESSION_TOKEN_FILE
+ "HERMES_DASHBOARD_SESSION_TOKEN=file:"
+ + (cfg.launchd.agents.hermes-backend.config.EnvironmentVariables.HERMES_DASHBOARD_SESSION_TOKEN
or "")
else
lib.concatStringsSep "\n" cfg.systemd.user.services.hermes-backend.Service.Environment;
@@ -547,7 +548,8 @@ json.dump(sorted(leaf_paths(DEFAULT_CONFIG)), sys.stdout, indent=2)
!lib.hasInfix tokenFile wrapper || !lib.hasInfix "--run" wrapper
) "the launcher must read the token from ${tokenFile} at start time, with --run"
++ lib.optional (
- !lib.hasInfix "HERMES_DASHBOARD_SESSION_TOKEN_FILE=${tokenFile}" backendTokenText
+ !lib.hasInfix "HERMES_DASHBOARD_SESSION_TOKEN=" backendTokenText
+ || !lib.hasInfix "file:${tokenFile}" backendTokenText
) "the backend unit must name the token file in its environment, or hermes mints a token the application cannot know"
# With no waitFor, a token must no longer force the launcher:
# nothing in the command line has to read a secret any more.
diff --git a/nix/moduleCommon.nix b/nix/moduleCommon.nix
index 07d23358a8f..173394940c7 100644
--- a/nix/moduleCommon.nix
+++ b/nix/moduleCommon.nix
@@ -952,7 +952,8 @@ let
# The token never rides through this script: it travels as a file path in
# the unit environment (backendSessionEnvironment), which is not a secret,
# and hermes reads the file itself at startup
- # (HERMES_DASHBOARD_SESSION_TOKEN_FILE). A shell wrapper that read the file
+ # as HERMES_DASHBOARD_SESSION_TOKEN=file:<path>, which hermes expands). A
+ # shell wrapper that read the file
# had to escapeShellArg the path, which froze any "${XDG_RUNTIME_DIR}"
# placeholder into a literal and crash-looped the unit (agenix's Home
# Manager module default). Set an absolute path instead; see the option
@@ -1040,9 +1041,9 @@ let
# The session token travels as a file path, never as the token itself. A
# path is not a secret, so it can sit in a systemd Environment= or a
# launchd EnvironmentVariables value without putting anything readable
- # into the store, and hermes reads the file itself at startup
- # (HERMES_DASHBOARD_SESSION_TOKEN_FILE), failing loudly when the file is
- # missing or empty.
+ # into the store. hermes expands the file: prefix of
+ # HERMES_DASHBOARD_SESSION_TOKEN and reads that file at startup, failing
+ # loudly when it is missing or empty.
#
# The path must be absolute. A "$XDG_RUNTIME_DIR"-style placeholder that a
# secret manager left for a shell to expand is passed through verbatim and
@@ -1052,7 +1053,7 @@ let
backendSessionEnvironment =
{ cfg }:
lib.optionalAttrs (cfg.backend.sessionTokenFile != null) {
- HERMES_DASHBOARD_SESSION_TOKEN_FILE = cfg.backend.sessionTokenFile;
+ HERMES_DASHBOARD_SESSION_TOKEN = "file:" + cfg.backend.sessionTokenFile;
};
backendArgv =