Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat: add Nix flake for packaging (#502)

marktodabee58c66815d
diff --git a/.gitignore b/.gitignore
index 713d61a62..355c8f431 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,7 @@ test-concurrent.sh
*.snap.pending
logo-variant-*.png
test-results/
+
+# Nix build outputs
+/result
+/result-*
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 000000000..156c928e9
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,98 @@
+{
+ "nodes": {
+ "crane": {
+ "locked": {
+ "lastModified": 1767744144,
+ "narHash": "sha256-9/9ntI0D+HbN4G0TrK3KmHbTvwgswz7p8IEJsWyef8Q=",
+ "owner": "ipetkov",
+ "repo": "crane",
+ "rev": "2fb033290bf6b23f226d4c8b32f7f7a16b043d7e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "ipetkov",
+ "repo": "crane",
+ "type": "github"
+ }
+ },
+ "flake-utils": {
+ "inputs": {
+ "systems": "systems"
+ },
+ "locked": {
+ "lastModified": 1731533236,
+ "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1767892417,
+ "narHash": "sha256-dhhvQY67aboBk8b0/u0XB6vwHdgbROZT3fJAjyNh5Ww=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "3497aa5c9457a9d88d71fa93a4a8368816fbeeba",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixos-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "crane": "crane",
+ "flake-utils": "flake-utils",
+ "nixpkgs": "nixpkgs",
+ "rust-overlay": "rust-overlay"
+ }
+ },
+ "rust-overlay": {
+ "inputs": {
+ "nixpkgs": [
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1767926800,
+ "narHash": "sha256-x0n73J6ufD/EhDlVdcoAmF0OQHZ+b0a2cKDc8RZyt+o=",
+ "owner": "oxalica",
+ "repo": "rust-overlay",
+ "rev": "499e9eed88ff9494b6604205b42847e847dfeb91",
+ "type": "github"
+ },
+ "original": {
+ "owner": "oxalica",
+ "repo": "rust-overlay",
+ "type": "github"
+ }
+ },
+ "systems": {
+ "locked": {
+ "lastModified": 1681028828,
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+ "owner": "nix-systems",
+ "repo": "default",
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-systems",
+ "repo": "default",
+ "type": "github"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 000000000..338df07d2
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,161 @@
+{
+ 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;
+ };
+
+ # Use latest stable Rust (must meet MSRV of 1.89)
+ rustToolchain = pkgs.rust-bin.stable.latest.default.override {
+ extensions = [ "rust-src" "rust-analyzer" ];
+ };
+
+ craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
+
+ # Filter source to include Cargo files plus templates (needed by askama)
+ src = pkgs.lib.cleanSourceWith {
+ src = ./.;
+ filter = path: type:
+ (craneLib.filterCargoSources path type)
+ || (pkgs.lib.hasInfix "/templates/" path)
+ || (builtins.baseNameOf (builtins.dirOf path) == "templates");
+ };
+
+ # 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 [
+ darwin.apple_sdk.frameworks.Security
+ darwin.apple_sdk.frameworks.SystemConfiguration
+ 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
+ # - Real system time (SOURCE_DATE_EPOCH breaks some tests)
+ # 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; };
+ };
+
+ 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"
+ '';
+ };
+ }
+ );
+}