Files
max-sixty__worktrunk/flake.nix
T
Maximilian Roos 57b303fda2 fix(nix): provide lsof to the flake's test sandbox (#3410)
The nix-flake job has failed on main since #3396:
`test_remove_reap_kills_process` discovers its child via `lsof -d cwd`,
but the flake's `worktrunk-tests` check didn't provide `lsof`, so
`processes_under` fails to spawn it, returns an empty list forever, and
the test's 5s discovery poll panics with `child <pid> never discovered`.
Failing main run:
https://github.com/max-sixty/worktrunk/actions/runs/29066326142.

Three changes:

- `flake.nix`: add `pkgs.lsof` to the test check's inputs, the same
pattern as `git`/`python3`/`procps`. `ps` (procps) already works in the
sandbox, so /proc-based process inspection is available there and the
test should be genuinely exercised rather than excluded.
- `.github/workflows/nightly.yaml`: add `flake.nix`, `flake.lock`, and
`nix/**` to the trigger paths (push and PR gate). A flake change
couldn't previously trigger the nix-flake job that validates it; this PR
relies on the fixed trigger for its own validation.
- `tests/integration_tests/remove.rs`: point the discovery-timeout panic
message at lsof, so the next environment missing it doesn't need
re-diagnosing.

Validation: nix isn't available locally, so the proof is this PR's own
nightly run going green on the nix-flake job.

> _This was written by Claude Code on behalf of max_

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-09 23:29:40 -07:00

238 lines
7.2 KiB
Nix

{
description = "Worktrunk - A CLI for Git worktree management";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
};
outputs =
{
self,
nixpkgs,
flake-utils,
rust-overlay,
crane,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
# Pin to the channel declared in rust-toolchain.toml so rustup and Nix
# stay on the same version. Extensions are dev-shell-only, so we keep
# them here rather than in rust-toolchain.toml (which CI also reads).
toolchainChannel = (builtins.fromTOML (builtins.readFile ./rust-toolchain.toml)).toolchain.channel;
rustToolchain = pkgs.rust-bin.stable.${toolchainChannel}.default.override {
extensions = [
"rust-src"
"rust-analyzer"
];
};
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
# Filter source to include Cargo files plus templates (needed by askama)
# and the Gemini extension manifest (embedded via include_str! in
# src/testing/mod.rs; lives at the repo root because Gemini's loader
# reads it only from the clone root — see #2807).
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter =
p: type:
(craneLib.filterCargoSources p type)
|| (pkgs.lib.hasInfix "/templates/" p)
|| (baseNameOf (dirOf p) == "templates")
|| (pkgs.lib.hasInfix "/dev/" p)
|| (baseNameOf (dirOf p) == "dev")
|| (baseNameOf p == "gemini-extension.json");
};
# Common arguments for crane builds
commonArgs = {
inherit src;
strictDeps = true;
nativeBuildInputs = with pkgs; [
pkg-config
];
buildInputs =
with pkgs;
[
# Required for tree-sitter (syntax-highlighting feature, enabled by default)
tree-sitter
]
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
libiconv
];
# vergen-gitcl needs git info; VERGEN_IDEMPOTENT makes it emit
# placeholder values when .git isn't available (which is the case
# in Nix builds since the store doesn't include .git)
VERGEN_IDEMPOTENT = "1";
# Optionally provide git describe via environment if flake has rev
VERGEN_GIT_DESCRIBE =
self.shortRev or self.dirtyShortRev or "nix-${self.lastModifiedDate or "unknown"}";
};
# Build just the cargo dependencies for caching.
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Build the actual package
worktrunk = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
# Skip tests during package build - they require snapshot files (insta)
# which bloat the source. Tests should run in CI instead.
doCheck = false;
meta = with pkgs.lib; {
description = "A CLI for Git worktree management, designed for parallel AI agent workflows";
homepage = "https://github.com/max-sixty/worktrunk";
license = with licenses; [
mit
asl20
];
maintainers = [ ];
mainProgram = "wt";
};
}
);
# Build with git-wt feature for Windows compatibility
worktrunk-with-git-wt = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
cargoExtraArgs = "--features git-wt";
doCheck = false;
meta = worktrunk.meta // {
description = "Worktrunk with git-wt binary (for 'git wt' subcommand)";
};
}
);
in
{
checks = {
inherit worktrunk;
# Run clippy
worktrunk-clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
# Check formatting
worktrunk-fmt = craneLib.cargoFmt { inherit src; };
# Run tests inside the nix sandbox. Catches packaging-environment
# bugs (#2624 is the canonical example) before nixpkgs maintainers
# do — see .github/workflows/nightly.yaml.
#
# Wider src than the package build: tests need .snap files and
# tests/ fixtures (prebuilt _git/ trees, .sh scripts, no-extension
# git database files). Default features only — shell-integration-
# tests requires zsh/fish/nushell + PTY (see CLAUDE.md → "Shell/PTY
# Integration Tests").
worktrunk-tests = craneLib.cargoTest (
commonArgs
// {
inherit cargoArtifacts;
src = pkgs.lib.cleanSource ./.;
# Tests shell out to a few host tools — `git` for the harness,
# `python3` for argv-quoting and post-start fixtures, `ps`
# (procps) for the pgid invariant test, `lsof` for the
# `--reap` process-discovery test. Without these on PATH
# the sandbox surfaces them as `No such file or directory`.
nativeBuildInputs = commonArgs.nativeBuildInputs ++ [
pkgs.git
pkgs.python3
pkgs.procps
pkgs.lsof
];
}
);
};
packages = {
default = worktrunk;
inherit worktrunk;
inherit worktrunk-with-git-wt;
};
apps = {
default = flake-utils.lib.mkApp {
drv = worktrunk;
name = "wt";
};
wt = flake-utils.lib.mkApp {
drv = worktrunk;
name = "wt";
};
};
devShells.default = craneLib.devShell {
checks = self.checks.${system};
packages = with pkgs; [
# Rust tooling
cargo-watch
cargo-edit
cargo-outdated
cargo-release
cargo-llvm-cov
# For shell integration tests
bash
zsh
fish
# Development tools
git
gh
pre-commit
];
shellHook = ''
echo "Worktrunk development shell"
echo " Build: cargo build"
echo " Test: cargo test"
echo " Lint: cargo clippy"
'';
};
}
)
// {
homeModules = {
default =
{
lib,
config,
pkgs,
...
}:
(import ./nix/home-manager-module.nix) {
inherit lib config pkgs;
worktrunk-pkgs = self.packages.${pkgs.stdenv.hostPlatform.system};
};
};
};
}