fix: inherit systemd environment.d in Flatpak #6

Merged
BlackHatMagic merged 3 commits from fix/flatpak-env into master 2026-10-25 07:29:02 +00:00

PR Type Selection

  • 🐛 Bug Fix

Problem

Obsidian Flatpak does not inherit the systemd user environment. On silverquill, PROVIDER_PROXY_URL and NODE_EXTRA_CA_CERTS live in ~/.config/environment.d/provider-proxy.conf. Terminal Pi sees them; the plugin's Pi child did not, so it fell back to http://127.0.0.1:8085 and returned Connection error.

Fix

piEnvironment() now reads host environment.d fragments ($XDG_CONFIG_HOME, ~/.config, and ~/.dotfiles/.config), applies values only when the child environment does not already set them, and skips PATH/HOME. Combined with the earlier host XDG_STATE_HOME mapping, the Pi child now matches terminal Pi exactly for provider-proxy URL, CA trust, and token.

Verification

  • Deployed the build to the Anastasia vault on silverquill.
  • Verified inside the Obsidian Flatpak sandbox with the resolved env: pi --list-models lists the proxy catalog and pi -p "Reply with exactly OK" returns OK.
  • Added an environment.d parsing test; bun run check passes with 39 tests; build passes.
  • Release 0.4.1.
## PR Type Selection - [x] 🐛 **Bug Fix** ## Problem Obsidian Flatpak does not inherit the systemd user environment. On silverquill, `PROVIDER_PROXY_URL` and `NODE_EXTRA_CA_CERTS` live in `~/.config/environment.d/provider-proxy.conf`. Terminal Pi sees them; the plugin's Pi child did not, so it fell back to `http://127.0.0.1:8085` and returned `Connection error.` ## Fix `piEnvironment()` now reads host `environment.d` fragments (`$XDG_CONFIG_HOME`, `~/.config`, and `~/.dotfiles/.config`), applies values only when the child environment does not already set them, and skips `PATH`/`HOME`. Combined with the earlier host `XDG_STATE_HOME` mapping, the Pi child now matches terminal Pi exactly for provider-proxy URL, CA trust, and token. ## Verification - Deployed the build to the Anastasia vault on silverquill. - Verified inside the Obsidian Flatpak sandbox with the resolved env: `pi --list-models` lists the proxy catalog and `pi -p "Reply with exactly OK"` returns `OK`. - Added an environment.d parsing test; `bun run check` passes with 39 tests; build passes. - Release 0.4.1.
Code-Reviewer left a comment

Pi code review

2 new actionable findings

  • [P2] Later environment.d overrides are ignored — src/launcher.ts:320
  • [P2] Unexpanded environment.d references break CA loading — src/launcher.ts:316

Merged the candidate reviews against pinned head 5df43f5 and base 7d7d6e8, 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
Area Files Changes
Other code (3) src/launcher.ts, manifest.json, versions.json Read host environment.d fragments into missing or empty child environment variables, excluding PATH and HOME. Bump the plugin version to 0.4.1. Record Obsidian compatibility for release 0.4.1.
Tests (1) tests/launcher.test.ts Test provider-setting imports and preservation of an inherited nonempty value.
Deployment & tooling (1) package.json Bump the package version to 0.4.1.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 5 files, +56/-3.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 5df43f535fa1025377b1448f66a2aa2601c68d1a with proxy/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.

<!-- forgejo-pi-review:8aa4904b0f785fb052a59b2d401a5e757fdf383b4d8711a32ea252e524d410f8 --> ## Pi code review **2 new actionable findings** - **[P2] Later environment.d overrides are ignored** — `src/launcher.ts:320` - **[P2] Unexpanded environment.d references break CA loading** — `src/launcher.ts:316` Merged the candidate reviews against pinned head 5df43f5 and base 7d7d6e8, 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. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (3) | `src/launcher.ts`, `manifest.json`, `versions.json` | Read host environment.d fragments into missing or empty child environment variables, excluding PATH and HOME. Bump the plugin version to 0.4.1. Record Obsidian compatibility for release 0.4.1. | | Tests (1) | `tests/launcher.test.ts` | Test provider-setting imports and preservation of an inherited nonempty value. | | Deployment & tooling (1) | `package.json` | Bump the package version to 0.4.1. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 5 files, +56/-3. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `5df43f535fa1025377b1448f66a2aa2601c68d1a` with `proxy/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]!;
Collaborator

[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.

**[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.
src/launcher.ts Outdated
@ -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;
Collaborator

[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.

**[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.
BlackHatMagic deleted branch fix/flatpak-env 2026-10-25 07:29:02 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
BlackHatMagic/Pi-Obsidian!6
No description provided.