Skip to content

feat: add Nix flake for reproducible builds#99

Closed
gitmpr wants to merge 3 commits into
timvw:mainfrom
gitmpr:feat/nix-flake
Closed

feat: add Nix flake for reproducible builds#99
gitmpr wants to merge 3 commits into
timvw:mainfrom
gitmpr:feat/nix-flake

Conversation

@gitmpr

@gitmpr gitmpr commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds flake.nix and flake.lock so wt can be installed via the Nix package manager
  • Users can install with nix profile install github:timvw/wt or run directly with nix run github:timvw/wt
  • Version string is injected at build time via ldflags (-X github.com/timvw/wt/cmd.Version=<version>)

Install

# Run directly
nix run github:timvw/wt -- version

# Install to profile
nix profile install github:timvw/wt

Sandbox notes

The full test suite passes without skipping any tests. Three Nix build sandbox quirks required explicit handling:

  • git, bash, util-linux in nativeCheckInputs — tests need git in PATH, a reachable bash binary, and script(1) (from util-linux), which the wt shell function uses to allocate a PTY for interactive commands
  • postPatch shebang rewriteTestRemoveCleansUpResidualWorktreeDirectory generates a #!/usr/bin/env bash wrapper script at runtime, but /usr/bin/env is absent in the Nix sandbox; the patch rewrites it to an absolute nix store path
  • preCheck git init — the sandbox strips .git from the source tree; TestGetAvailableBranches and TestDefaultCmdRunsWithoutError call git in the working directory, so preCheck initialises a fresh repo

Test plan

  • nix build .#wt passes (all tests, no -short flag)
  • ./result/bin/wt version prints wt version 0.1.29

gitmpr added 3 commits June 29, 2026 18:58
Adds flake.nix and flake.lock providing a Nix-native install path:

  nix run github:gitmpr/wt
  nix profile install github:gitmpr/wt

The build uses buildGoModule with vendorHash and injects the version
string via ldflags. Three sandbox quirks are handled explicitly:

- git, bash, util-linux in nativeCheckInputs so tests have git,
  script(1), and a bash binary reachable by absolute path
- postPatch rewrites #!/usr/bin/env bash in the runtime-generated test
  helper to an absolute nix store path, since /usr/bin/env is absent
  from the Nix build sandbox
- preCheck initialises a git repo in the source tree so tests that
  call git in the working directory (TestGetAvailableBranches,
  TestDefaultCmdRunsWithoutError) find a valid repository
@timvw timvw closed this in #100 Jul 6, 2026
timvw added a commit that referenced this pull request Jul 6, 2026
Nix flake packaging for wt. Builds on @gitmpr's #99 (their commits preserved) with review + codex fixes: exclude the internal e2e binary, version-from-git-rev, bash via LookPath, git bundled in runtime PATH, util-linux gated to Linux, corrected NixOS/home-manager docs. Adds a pinned Linux Nix CI job and a Dockerfile for local repro.

Co-authored-by: gitmpr <89863774+gitmpr@users.noreply.github.com>
@timvw

timvw commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Thank you so much for this, @gitmpr! 🙏 Your flake was the foundation here — the sandbox workarounds (nativeCheckInputs, the git init in preCheck, the shebang handling) were spot on and did the hard part.

We folded your commits into #100 (preserved with a Co-authored-by on the squash) and layered on some follow-ups from a review pass: excluding the internal e2e main package so only wt is installed, deriving the version from the git rev to avoid drift, resolving bash via exec.LookPath (which let us drop the postPatch shebang rewrite entirely), bundling git in the runtime PATH, gating util-linux to Linux, and a Linux Nix CI job + Dockerfile so the flake stays tested.

#100 is merged, so I'll close this one — but the credit is yours. Really appreciate you adding Nix support! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants