Repository navigation
Conversation
The runtime download has an FHS interpreter and cannot launch on NixOS without nix-ld or manual patching. Package the Chrome for Testing shell pinned by T3 Code and fix its ELF interpreter and library paths at build time. Redirect the installed-browser lookup to that store executable. Expose the browser through passthru and check the upstream version pin when patching T3 Code, so release updates cannot silently use a different browser. Add a NixOS VM test that renders a page and saves a screenshot as a normal user with Chrome's sandbox enabled. The browser derivation is based on OSSystems/t3code-nix, with the store layout and integration adapted for nixpkgs. Assisted-by: Codex (gpt-6.1-sol)
0x4bs3nt
left a comment
There was a problem hiding this comment.
the packaged-browser approach addresses the missing libraries and ELF interpreter behind #582297.
however, please update the apparmor integration for the new exec location. PreviewBrowserHost.ts generates a profile matching only /**/tools/chrome-headless-shell/*/*/chrome-headless-shell, whereas this change launches the browser from /nix/store/…/libexec/t3code-browser/chrome-headless-shell. on Ubuntu hosts enforcing user namespace restrictions, the profile will no longer cover the browser.
make the profile cover the packaged executable and handle updating an already installed profile.
the separate installedBrowser lookup in cli/browser.ts should also use the packaged executable, otherwise setup continues diagnosing stale cached downloads.
please add Closes #582297 to the description as well.
Match the canonical packaged executable in the AppArmor profile. Key its profile name and filename by the browser store path so an existing cache-only profile, or one for an older store result, cannot make setup skip registration. Keep those older profiles available to other T3 installations. Use the same packaged executable for setup's library diagnostics rather than scanning cached runtime downloads. Validated profile migration with a restricted-host filesystem fixture, profile parsing and kernel attachment in an AppArmor-enabled NixOS VM, and setup with a stale cached browser. The full t3code build passes. Assisted-by: Codex (gpt-6.1-sol)
|
Addressed in 48f8576.
Validation passed: full Assisted by Codex (gpt-6.1-sol). |
0x4bs3nt
left a comment
There was a problem hiding this comment.
changes look good to me, i'd have loved if this was tested on ubuntu, but approving.
RossSmyth
left a comment
There was a problem hiding this comment.
Looking upstream this seems to act as a web browser (meaning you can use it to browse the web), meaning that it falls under the Nixpkgs browser security rules:
- Upstream must keep up-to-date with their upstream (Chromium it seems in this case) and able to release non-trivial updates from their upstream within a few hours.
- An active nixpkgs committer is listed in this package to merge patches within a few hours, generally once or twice a week.
These rules exist because browser are of particular importance in our security profile; they process untrusted inputs by design.
https://nvd.nist.gov/vuln/search?cpeFilterMode=cpe&cpeName=cpe:2.3:a:google:chrome:156.0.8078.70:*:*:*:*:*:*:*&resultType=records
Use the existing Chromium package so browser security updates do not depend on T3 Code releases or a separately maintained binary pin. Remove the private Chrome for Testing derivation and its version check. Keep setup and rendering on the same browser, with AppArmor matching Chromium's canonical executable. Add a VM regression test for setup with empty and stale caches, and for rendering with the sandbox enabled. T3 Code's screenshot, layout measurement, and Playwright incognito and persistent contexts work with Chromium 156.0.8078.79. The full package build and both the regression and AppArmor VM checks pass. Assisted-by: Codex (gpt-6.1-sol)
|
Agreed. I revised the PR in 82dad32 to use the existing nixpkgs The separate pinned Chrome for Testing derivation and its version check are removed. Browser engine updates now follow the existing Chromium package, independently of T3 releases, reusing its source build and maintenance. Both setup diagnostics and rendering use that dependency, and the AppArmor profile matches Chromium’s actual executable. Compatibility checks passed with T3 Code v0.1.6 and Chromium 156.0.8078.79: T3’s screenshot/layout-measurement functions and Playwright incognito/persistent contexts, with the sandbox enabled. The full package build, a new NixOS VM regression test for empty/stale caches and sandboxed rendering, and the AppArmor attachment VM also pass. The description now covers this implementation and validation. Assisted by Codex (gpt-6.1-sol). |
|
Maybe we can also use |
|
Think I prefer this approach vs the other pr, but I'd agree with @merrkry that gets us shipping the same as upstream, basically. (though release cadence could be a negative vs shipping whole chromium, see #585789 ) I'd prefer not to use chromium when considering #555814 , as shipping headless would be feasible in the -cli version, but shipping chromium would lose ~all of the upside (not shipping electron) |
| { | ||
| callPackage, | ||
| cctools, | ||
| chromium, | ||
| copyDesktopItems, |
There was a problem hiding this comment.
Move browser wiring to package.nix (via T3CODE_BROWSER_PATH, matching T3CODE_CLOUDFLARED_PATH / T3CODE_RESOURCE_MONITOR_PATH) so overriding or disabling the browser doesn't rebuild unwrapped.
| { | |
| callPackage, | |
| cctools, | |
| chromium, | |
| copyDesktopItems, | |
| { | |
| cctools, | |
| copyDesktopItems, |
| pnpm = pnpm_12; | ||
| browser = chromium; | ||
| browserProfileName = "t3-nix-${builtins.baseNameOf (toString browser.browser)}"; | ||
| withBrowser = lib.elem stdenv.hostPlatform.system [ | ||
| "x86_64-linux" | ||
| "aarch64-linux" | ||
| ]; | ||
| desktopIcon = |
There was a problem hiding this comment.
| pnpm = pnpm_12; | |
| browser = chromium; | |
| browserProfileName = "t3-nix-${builtins.baseNameOf (toString browser.browser)}"; | |
| withBrowser = lib.elem stdenv.hostPlatform.system [ | |
| "x86_64-linux" | |
| "aarch64-linux" | |
| ]; | |
| desktopIcon = | |
| pnpm = pnpm_12; | |
| desktopIcon = |
| '' | ||
| + lib.optionalString withBrowser '' | ||
| substituteInPlace apps/server/src/preview/PreviewBrowser.ts \ | ||
| --replace-fail 'const executable = path.join(installRoot, release.version, executableName);' \ | ||
| 'const executable = "${lib.getExe browser}";' | ||
|
|
||
| # Key the profile by store path so setup also runs after browser updates | ||
| # or when an upstream cache-only profile is already installed. | ||
| substituteInPlace apps/server/src/preview/PreviewBrowserHost.ts \ | ||
| --replace-fail 't3-chrome-headless-shell' '${browserProfileName}' \ | ||
| --replace-fail '/**/tools/chrome-headless-shell/*/*/chrome-headless-shell' \ | ||
| '${browser.browser}/libexec/chromium/chromium' | ||
|
|
||
| substituteInPlace apps/server/src/cli/browser.ts \ | ||
| --replace-fail 'const browser = yield* installedBrowser(baseDirPath);' \ | ||
| 'const browser = Option.some("${lib.getExe browser}");' | ||
| ''; |
There was a problem hiding this comment.
Read T3CODE_BROWSER_PATH (and optional T3CODE_BROWSER_APPARMOR_PATH for Chromium's canonical ELF) at runtime, falling back to upstream behavior when unset.
| '' | |
| + lib.optionalString withBrowser '' | |
| substituteInPlace apps/server/src/preview/PreviewBrowser.ts \ | |
| --replace-fail 'const executable = path.join(installRoot, release.version, executableName);' \ | |
| 'const executable = "${lib.getExe browser}";' | |
| # Key the profile by store path so setup also runs after browser updates | |
| # or when an upstream cache-only profile is already installed. | |
| substituteInPlace apps/server/src/preview/PreviewBrowserHost.ts \ | |
| --replace-fail 't3-chrome-headless-shell' '${browserProfileName}' \ | |
| --replace-fail '/**/tools/chrome-headless-shell/*/*/chrome-headless-shell' \ | |
| '${browser.browser}/libexec/chromium/chromium' | |
| substituteInPlace apps/server/src/cli/browser.ts \ | |
| --replace-fail 'const browser = yield* installedBrowser(baseDirPath);' \ | |
| 'const browser = Option.some("${lib.getExe browser}");' | |
| ''; | |
| '' | |
| + lib.optionalString stdenv.hostPlatform.isLinux '' | |
| substituteInPlace apps/server/src/preview/PreviewBrowser.ts \ | |
| --replace-fail 'const executable = path.join(installRoot, release.version, executableName);' \ | |
| 'const executable = process.env.T3CODE_BROWSER_PATH || path.join(installRoot, release.version, executableName);' | |
| # Key the AppArmor profile by the canonical browser store path at runtime so | |
| # setup tracks wrapper overrides and updates without rebuilding unwrapped. | |
| substituteInPlace apps/server/src/preview/PreviewBrowserHost.ts \ | |
| --replace-fail 'export const APPARMOR_PROFILE_PATH = "/etc/apparmor.d/t3-chrome-headless-shell";' \ | |
| 'const nixBrowserAppArmorPath = process.env.T3CODE_BROWSER_APPARMOR_PATH || process.env.T3CODE_BROWSER_PATH; | |
| const nixBrowserProfileName = nixBrowserAppArmorPath ? `t3-nix-''${nixBrowserAppArmorPath.split("/")[3] ?? "browser"}` : "t3-chrome-headless-shell"; | |
| export const APPARMOR_PROFILE_PATH = `/etc/apparmor.d/''${nixBrowserProfileName}`;' \ | |
| --replace-fail 'profile t3-chrome-headless-shell /**/tools/chrome-headless-shell/*/*/chrome-headless-shell flags=(unconfined) {' \ | |
| 'profile ''${nixBrowserProfileName} ''${nixBrowserAppArmorPath || "/**/tools/chrome-headless-shell/*/*/chrome-headless-shell"} flags=(unconfined) {' \ | |
| --replace-fail 'include if exists <local/t3-chrome-headless-shell>' \ | |
| 'include if exists <local/''${nixBrowserProfileName}>' | |
| substituteInPlace apps/server/src/cli/browser.ts \ | |
| --replace-fail 'const browser = yield* installedBrowser(baseDirPath);' \ | |
| 'const browser = env.T3CODE_BROWSER_PATH ? Option.some(env.T3CODE_BROWSER_PATH) : yield* installedBrowser(baseDirPath);' | |
| ''; |
| } | ||
| // lib.optionalAttrs withBrowser { | ||
| inherit browser; | ||
| tests.browser = callPackage ./browser-test.nix { | ||
| inherit browser; | ||
| t3code = finalAttrs.finalPackage; | ||
| }; | ||
| }; |
There was a problem hiding this comment.
Move passthru.browser and passthru.tests.browser to package.nix so the VM test exercises the wrapped t3code package.
| } | |
| // lib.optionalAttrs withBrowser { | |
| inherit browser; | |
| tests.browser = callPackage ./browser-test.nix { | |
| inherit browser; | |
| t3code = finalAttrs.finalPackage; | |
| }; | |
| }; | |
| }; |
|
Context for the inline suggestions on
Companion diff for --- a/pkgs/by-name/t3/t3code/package.nix
+++ b/pkgs/by-name/t3/t3code/package.nix
@@ -1,8 +1,10 @@
{
lib,
+ stdenv,
callPackage,
symlinkJoin,
makeBinaryWrapper,
+ chromium,
enableAzureDevOps ? false,
azure-cli,
azure-cli-extensions,
@@ -26,11 +28,23 @@
enableOpencode ? false,
opencode,
enableResourceMonitor ? true,
+ enableBrowser ? lib.elem stdenv.hostPlatform.system [
+ "x86_64-linux"
+ "aarch64-linux"
+ ],
+ browser ? chromium,
t3code-unwrapped ? callPackage ./unwrapped.nix { },
t3code-resource-monitor ? callPackage ./resource-monitor.nix { inherit t3code-unwrapped; },
}:
let
+ browserExe = lib.getExe browser;
+ # Chromium's `lib.getExe` is a wrapper script; AppArmor needs the canonical ELF.
+ browserAppArmorPath =
+ if browser ? browser then
+ "${browser.browser}/libexec/chromium/chromium"
+ else
+ browserExe;
+
runtimePackages =
lib.optionals enableAzureDevOps [
(azure-cli.withExtensions [ azure-cli-extensions.azure-devops ])
@@ -62,10 +76,18 @@ let
"--set-default"
"T3CODE_RESOURCE_MONITOR_PATH"
(lib.getExe t3code-resource-monitor)
+ ]
+ ++ lib.optionals (enableBrowser && browser != null) [
+ "--set-default"
+ "T3CODE_BROWSER_PATH"
+ browserExe
+ "--set-default"
+ "T3CODE_BROWSER_APPARMOR_PATH"
+ browserAppArmorPath
];
in
-symlinkJoin {
+symlinkJoin (finalAttrs: {
pname = "t3code";
inherit (t3code-unwrapped) version;
__structuredAttrs = true;
@@ -85,7 +107,14 @@ symlinkJoin {
unwrapped = t3code-unwrapped;
resourceMonitor = t3code-resource-monitor;
}
- // t3code-unwrapped.passthru;
+ // t3code-unwrapped.passthru
+ // lib.optionalAttrs (enableBrowser && browser != null) {
+ inherit browser;
+ tests.browser = callPackage ./browser-test.nix {
+ inherit browser;
+ t3code = finalAttrs.finalPackage;
+ };
+ };
meta = {
# Manually inherit so that pos works
@@ -100,4 +129,4 @@ symlinkJoin {
platforms
;
};
-}
+})Note: |
Closes #582297.
T3 Code downloads a headless browser whose FHS interpreter and shared-library lookup do not work on NixOS without nix-ld or manual patching. Use nixpkgs’ existing source-built
chromiumpackage for Linux previews and HTML rendering instead. The browser can receive nixpkgs security updates independently of T3 Code releases, without introducing another pinned browser build or maintenance role.Both the renderer and
t3 browser setupuse the packaged executable. Setup no longer diagnoses stale cached downloads.t3code.browserexposes the Chromium dependency.The generated AppArmor profile matches Chromium’s exact canonical executable, rather than its launcher script. Its name and filename include that executable’s store hash, so an upstream cache-only profile or a profile for another store result cannot cause setup to skip registration. Older profiles remain available to other installations. No broad store-path wildcard is used.
Integration applies on x86_64-linux and aarch64-linux. Darwin and unsupported Linux systems retain the upstream browser lookup without evaluating Chromium’s unsupported dependencies.
Validation with T3 Code v0.1.6 and Chromium 156.0.8078.79:
nix-build -A t3code -A t3code.tests.browser --no-out-linkpassed with sandboxing enabled on x86_64-linux. The VM test checks setup with an empty cache, setup with a stale downloaded browser that must not execute, and page rendering plus a screenshot as a normal user with Chrome’s sandbox enabled. The VM has no nix-ld configuration.PreviewBrowserHost.ts, launched Chromium, and confirmed the generated profile through/proc/<pid>/attr/current. A restricted-host filesystem fixture also checks legacy/current profile detection and browser-store updates. A full Ubuntu restricted-userns test is not claimed.t3code-browserderivation.nixfmt --checkandgit diff --checkpass.Code, tests, commit messages, description, and the local compatibility/AppArmor probes were assisted by Codex (gpt-6.1-sol).
Things done
./result/bin/.nixpkgs-reviewon this PR. See nixpkgs-review usage.passthru.tests.