Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changesets

This project uses [Changesets](https://github.com/changesets/changesets) for versioning.
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
"changelog": ["@changesets/changelog-github", { "repo": "yimsk/opencode-workspace-env" }],
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/filter-system-identity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"opencode-workspace-env": patch
---

Filter system identity variables (HOME, USER, LOGNAME, SHELL, HOSTNAME) from env injection to prevent overriding host values
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release

on:
push:
branches: [main]

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install

- name: Create release PR or publish
uses: changesets/action@v1
with:
version: bunx changeset version
publish: npm publish
title: "chore: release"
commit: "chore: release"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
214 changes: 207 additions & 7 deletions bun.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"license": "MIT",
"repository": "github:yimsk/opencode-workspace-env",
"devDependencies": {
"@changesets/changelog-github": "^0.6.0",
"@changesets/cli": "^2.30.0",
"@nkzw/oxlint-config": "^1.0.1",
"@types/bun": "latest",
"@types/node": "^24.5.2",
Expand Down
5 changes: 5 additions & 0 deletions src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const EXCLUDED_PREFIXES = ["DIRENV_", "NIX_BUILD_", "__"];

/** Known nix build-system variables that should not leak into shell env */
const EXCLUDED_VARS = new Set([
"HOME",
"USER",
"LOGNAME",
"SHELL",
"HOSTNAME",
"name",
"system",
"builder",
Expand Down
23 changes: 23 additions & 0 deletions tests/direnv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,27 @@ describe("exportEnv", () => {
TEST_VAR: "keep",
});
});

it("should filter out system identity variables", async () => {
mockDirenv(() => ({
stdout: JSON.stringify({
HOME: "/homeless-shelter",
HOSTNAME: "build-host",
LOGNAME: "nixbld",
SHELL: "/nix/store/.../bash",
TEST_VAR: "keep",
USER: "nixbld",
}),
success: true,
}));

const result = await exportEnv(envrcPath);

expect(result.ok).toBeTrue();
if (!result.ok) {
throw new Error("expected ok");
}

expect(result.env).toEqual({ TEST_VAR: "keep" });
});
});
27 changes: 25 additions & 2 deletions tests/nix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe("exportNixEnv", () => {
stdout: JSON.stringify({
variables: {
CUSTOM_VAR: { type: "exported", value: "custom_value" },
HOME: { type: "exported", value: "/home/user" },
PATH: { type: "exported", value: "/nix/store/...:..." },
},
}),
Expand All @@ -45,7 +44,6 @@ describe("exportNixEnv", () => {
expect(result).toEqual({
env: {
CUSTOM_VAR: "custom_value",
HOME: "/home/user",
PATH: "/nix/store/...:...",
},
ok: true,
Expand Down Expand Up @@ -237,4 +235,29 @@ describe("exportNixEnv", () => {
// NIX_BUILD_* should be filtered
expect(result.env.NIX_BUILD_CORES).toBeUndefined();
});

it("should filter out system identity variables", async () => {
mockNix(() => ({
stdout: JSON.stringify({
variables: {
CUSTOM_VAR: { type: "exported", value: "keep" },
HOME: { type: "exported", value: "/homeless-shelter" },
HOSTNAME: { type: "exported", value: "build-host" },
LOGNAME: { type: "exported", value: "nixbld" },
SHELL: { type: "exported", value: "/nix/store/.../bash" },
USER: { type: "exported", value: "nixbld" },
},
}),
success: true,
}));

const result = await exportNixEnv(flakeNixPath);

expect(result.ok).toBeTrue();
if (!result.ok) {
throw new Error("expected ok");
}

expect(result.env).toEqual({ CUSTOM_VAR: "keep" });
});
});
Loading