generated from BlackHatMagic/Template-Bare
fix: inherit systemd environment.d in Flatpak #6
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/flatpak-env"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
PR Type Selection
Problem
Obsidian Flatpak does not inherit the systemd user environment. On silverquill,
PROVIDER_PROXY_URLandNODE_EXTRA_CA_CERTSlive in~/.config/environment.d/provider-proxy.conf. Terminal Pi sees them; the plugin's Pi child did not, so it fell back tohttp://127.0.0.1:8085and returnedConnection error.Fix
piEnvironment()now reads hostenvironment.dfragments ($XDG_CONFIG_HOME,~/.config, and~/.dotfiles/.config), applies values only when the child environment does not already set them, and skipsPATH/HOME. Combined with the earlier hostXDG_STATE_HOMEmapping, the Pi child now matches terminal Pi exactly for provider-proxy URL, CA trust, and token.Verification
pi --list-modelslists the proxy catalog andpi -p "Reply with exactly OK"returnsOK.bun run checkpasses with 39 tests; build passes.Pi code review
2 new actionable findings
src/launcher.ts:320src/launcher.ts:316Merged the candidate reviews against pinned head
5df43f5and base7d7d6e8, confirming two environment.d correctness issues through the launcher, session, and process-spawn code. Verification was read-only; no tests, build, or Flatpak execution were available.Change walkthrough
src/launcher.ts,manifest.json,versions.jsontests/launcher.test.tspackage.jsonReview effort: 3/5.
Static observations (not validation results)
Reviewed
5df43f535fa1025377b1448f66a2aa2601c68d1awithproxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.@ -295,0 +313,4 @@for (const line of readFileSync(join(dir, file), "utf8").split("\n")) {const match = line.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/);if (!match) continue;let value = match[2]!;[P2] Unexpanded environment.d references break CA loading
Compliance/correctness: the parser strips enclosing quotes but does not expand supported environment.d variable references. For example, NODE_EXTRA_CA_CERTS=${HOME}/.config/provider-proxy/ca.crt is passed to Node as a literal path rather than the resolved certificate path.
Trigger: A Flatpak user configures NODE_EXTRA_CA_CERTS using ${HOME} in a readable environment.d fragment, the certificate exists at the expanded host path, and NODE_EXTRA_CA_CERTS is absent from the inherited environment.
Impact: Node cannot load the additional CA from the literal path, so requests to an HTTPS provider proxy that relies on that CA fail even though terminal Pi uses the same configuration successfully.
Evidence: src/launcher.ts:316–320 captures the value, removes matching outer quotes, and stores it without reference expansion. piEnvironment then imports it unchanged at lines 334–337. src/session.ts:141 supplies that environment to PiClient, whose start method passes it directly to spawn without environment-value expansion. The added launcher test uses only literal URLs and absolute certificate paths.
@ -295,0 +317,4 @@if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {value = value.slice(1, -1);}if (!(match[1]! in result)) result[match[1]!] = value;[P2] Later environment.d overrides are ignored
Compliance/correctness: fragments are processed in ascending filename order, but the parser retains the first assignment to each variable. environment.d uses later assignments to override earlier ones, so a normal local override produces a different provider configuration from terminal Pi.
Trigger: A Flatpak user has no inherited PROVIDER_PROXY_URL and has a readable environment.d directory containing 10-defaults.conf and 90-local.conf that assign different proxy URLs.
Impact: The Pi child connects to the default or obsolete proxy instead of the configured override, causing connection or authentication failures despite a working terminal configuration.
Evidence: src/launcher.ts:307 sorts fragment names ascending, while line 320 assigns only when the key is absent from result, preventing every later assignment from taking effect. piEnvironment imports that first value at lines 334–337 when Flatpak has omitted the variable. PiSession.doStart passes piEnvironment() to PiClient at src/session.ts:141, and PiClient.start passes the environment directly to spawn; no downstream code corrects the precedence.