-
Notifications
You must be signed in to change notification settings - Fork 4
build(nix): add reproducible package and dev shell #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pmarreck
wants to merge
2
commits into
coder:main
Choose a base branch
from
pmarreck:feat/nix-flake
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+268
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,241 @@ | ||
| { | ||
| description = "Nix package and development shell for agent-tty"; | ||
|
|
||
| inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | ||
|
|
||
| outputs = { | ||
| self, | ||
| nixpkgs, | ||
| ... | ||
| }: let | ||
| systems = [ | ||
| "x86_64-linux" | ||
| "aarch64-linux" | ||
| "aarch64-darwin" | ||
| ]; | ||
| forAllSystems = nixpkgs.lib.genAttrs systems; | ||
| in { | ||
| packages = forAllSystems (system: let | ||
| pkgs = import nixpkgs {inherit system;}; | ||
| lib = pkgs.lib; | ||
| nodejs = pkgs.nodejs_26; | ||
|
|
||
| dependencySource = lib.fileset.toSource { | ||
| root = ./.; | ||
| fileset = lib.fileset.unions [ | ||
| ./package.json | ||
| ./aube-lock.yaml | ||
| ./pnpm-workspace.yaml | ||
| ]; | ||
| }; | ||
|
|
||
| packageSource = lib.fileset.toSource { | ||
| root = ./.; | ||
| fileset = lib.fileset.unions [ | ||
| ./package.json | ||
| ./aube-lock.yaml | ||
| ./pnpm-workspace.yaml | ||
| ./tsconfig.json | ||
| ./tsconfig.build.json | ||
| ./src | ||
| ./scripts | ||
| ./skills | ||
| ./skill-data | ||
| ]; | ||
| }; | ||
|
|
||
| # Aube's lockfile contains integrity hashes for every package, while this | ||
| # fixed-output derivation pins the complete downloaded cache. The package | ||
| # derivation below must then install with --offline. | ||
| dependencyCache = pkgs.stdenvNoCC.mkDerivation { | ||
| pname = "agent-tty-aube-cache"; | ||
| version = "0.5.0"; | ||
| src = dependencySource; | ||
|
|
||
| nativeBuildInputs = [ | ||
| pkgs.aube | ||
| pkgs.cacert | ||
| ]; | ||
|
|
||
| dontConfigure = true; | ||
| dontFixup = true; | ||
|
|
||
| buildPhase = '' | ||
| runHook preBuild | ||
|
|
||
| # Use Nixpkgs' pinned Aube. Package-manager self-switching would make | ||
| # the fetched tool another undeclared dependency of the build. | ||
| substituteInPlace package.json \ | ||
| --replace-fail ' "packageManager": "aube@1.2.0",' "" | ||
|
|
||
| export HOME="$TMPDIR/home" | ||
| export XDG_CACHE_HOME="$TMPDIR/cache" | ||
| export XDG_DATA_HOME="$TMPDIR/data" | ||
| mkdir -p "$HOME" "$XDG_CACHE_HOME" "$XDG_DATA_HOME" | ||
|
|
||
| aube fetch --frozen-lockfile --reporter append-only | ||
|
|
||
| runHook postBuild | ||
| ''; | ||
|
|
||
| installPhase = '' | ||
| runHook preInstall | ||
| mkdir -p "$out/cache" "$out/data" | ||
| cp -R "$XDG_CACHE_HOME"/. "$out/cache"/ | ||
| cp -R "$XDG_DATA_HOME"/. "$out/data"/ | ||
| runHook postInstall | ||
| ''; | ||
|
|
||
| outputHashMode = "recursive"; | ||
| outputHashAlgo = "sha256"; | ||
| outputHash = "sha256-U5oksqBtoQTDwVKwEXjgc9z3WRaMv7MVPyeK3/195oc="; | ||
| }; | ||
|
|
||
| agent-tty = pkgs.stdenvNoCC.mkDerivation { | ||
| pname = "agent-tty"; | ||
| version = "0.5.0"; | ||
| src = packageSource; | ||
|
|
||
| nativeBuildInputs = [ | ||
| pkgs.aube | ||
| nodejs | ||
| pkgs.python3 | ||
| pkgs.stdenv.cc | ||
| pkgs.gnumake | ||
| pkgs.pkg-config | ||
| pkgs.node-gyp | ||
| pkgs.makeWrapper | ||
| ]; | ||
|
|
||
| dontConfigure = true; | ||
|
|
||
| buildPhase = '' | ||
| runHook preBuild | ||
|
|
||
| substituteInPlace package.json \ | ||
| --replace-fail ' "packageManager": "aube@1.2.0",' "" | ||
|
|
||
| export HOME="$TMPDIR/home" | ||
| export XDG_CACHE_HOME="$TMPDIR/cache" | ||
| export XDG_DATA_HOME="$TMPDIR/data" | ||
| mkdir -p "$HOME" "$XDG_CACHE_HOME" "$XDG_DATA_HOME" | ||
| cp -R ${dependencyCache}/cache/. "$XDG_CACHE_HOME"/ | ||
| cp -R ${dependencyCache}/data/. "$XDG_DATA_HOME"/ | ||
| chmod -R u+w "$XDG_CACHE_HOME" "$XDG_DATA_HOME" | ||
|
|
||
| aube install \ | ||
| --offline \ | ||
| --frozen-lockfile \ | ||
| --ignore-scripts \ | ||
| --disable-global-virtual-store \ | ||
| --package-import-method copy \ | ||
| --reporter append-only | ||
|
|
||
| # node-pty has no Linux prebuild in the locked package. Build it with | ||
| # Nixpkgs' node-gyp so Aube never bootstraps a tool from the network. | ||
| ( | ||
| cd node_modules/node-pty | ||
| node-gyp rebuild | ||
| ) | ||
| npm run build | ||
|
|
||
| runHook postBuild | ||
| ''; | ||
|
|
||
| installPhase = '' | ||
| runHook preInstall | ||
|
|
||
| app="$out/lib/agent-tty" | ||
| production="$TMPDIR/production" | ||
| mkdir -p "$app" "$out/bin" | ||
|
|
||
| # Build tools are devDependencies, so compile first and then create a | ||
| # fresh production graph. Aube's in-place prune currently leaves | ||
| # dangling virtual-store links behind. | ||
| mkdir -p "$production" | ||
| cp package.json aube-lock.yaml pnpm-workspace.yaml "$production"/ | ||
| ( | ||
| cd "$production" | ||
| aube install \ | ||
| --prod \ | ||
| --offline \ | ||
| --frozen-lockfile \ | ||
| --ignore-scripts \ | ||
| --disable-global-virtual-store \ | ||
| --package-import-method copy \ | ||
| --reporter append-only | ||
|
|
||
| cd node_modules/node-pty | ||
| node-gyp rebuild | ||
| ) | ||
|
|
||
| cp -R dist package.json skills skill-data "$app"/ | ||
| cp -R "$production/node_modules" "$app"/ | ||
|
|
||
| makeWrapper ${nodejs}/bin/node "$out/bin/agent-tty" \ | ||
| --add-flags "$app/dist/cli/main.js" | ||
|
|
||
| runHook postInstall | ||
| ''; | ||
|
|
||
| meta = { | ||
| description = "Drive, inspect, and record terminal sessions from the CLI"; | ||
| homepage = "https://github.com/coder/agent-tty"; | ||
| license = lib.licenses.asl20; | ||
| mainProgram = "agent-tty"; | ||
| platforms = systems; | ||
| }; | ||
| }; | ||
| in { | ||
| default = agent-tty; | ||
| inherit agent-tty; | ||
| }); | ||
|
|
||
| checks = forAllSystems (system: let | ||
| pkgs = import nixpkgs {inherit system;}; | ||
| package = self.packages.${system}.default; | ||
| in { | ||
| inherit package; | ||
|
|
||
| smoke = | ||
| pkgs.runCommand "agent-tty-smoke" { | ||
| nativeBuildInputs = [ | ||
| package | ||
| pkgs.jq | ||
| ]; | ||
| } '' | ||
| export HOME="$TMPDIR/home" | ||
| mkdir -p "$HOME" | ||
|
|
||
| agent-tty version --json > version.json | ||
| doctor_exit=0 | ||
| agent-tty --home "$TMPDIR/agent-tty-home" doctor --json > doctor.json || doctor_exit=$? | ||
| printf '%s\n' "$doctor_exit" > doctor-exit-status | ||
| jq -e '.result.checks.environment[] | select(.name == "pty-spawn" and .status == "pass")' doctor.json | ||
|
|
||
| mkdir -p "$out" | ||
| cp version.json doctor.json doctor-exit-status "$out"/ | ||
| ''; | ||
| }); | ||
|
|
||
| devShells = forAllSystems (system: let | ||
| pkgs = import nixpkgs {inherit system;}; | ||
| in { | ||
| default = pkgs.mkShell { | ||
| packages = [ | ||
| pkgs.nodejs_26 | ||
| pkgs.aube | ||
| pkgs.zig_0_15 | ||
| pkgs.python3 | ||
| pkgs.stdenv.cc | ||
| pkgs.gnumake | ||
| pkgs.pkg-config | ||
| pkgs.git | ||
| pkgs.cacert | ||
| ]; | ||
| }; | ||
| }); | ||
|
|
||
| formatter = forAllSystems (system: (import nixpkgs {inherit system;}).alejandra); | ||
| }; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the next automated release updates
package.json, this hard-coded value—and the duplicate cache version at line 52—will remain0.5.0, becauserelease-please-config.json:10only registersREADME.mdas an extra versioned file. The resulting Nix package will therefore expose stale derivation metadata even though the bundled CLI reports the new version; derive this value frompackage.jsonor add both occurrences to the release update process.Useful? React with 👍 / 👎.