Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ node_modules
out
dist
*.tgz
result

# code coverage
coverage
Expand Down
1 change: 1 addition & 0 deletions .nix/nix-deps-hash.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sha256-Lr3M22JlMcX+HTZay2A1rN/zwGnznIjaib3E3y0Aob0=
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the hash might change across architectures (darwin/linux and x86/arm64). I can test this if needed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing it was also my first thought but I want to believe is there for an unknown reason to us and I usually try touching core files like package.json as little as possible.

Now that you speak about that I think you are right too. I can also test tomorrow at work where my machine has an ARM CPU. If our concerns are right then I don't think this is anymore a viable method. We would have to add a json file with one hash per architecture instead of a txt one and that is a maintenance nightmare.

We should use bun2nix if that happens but I just want to be sure that there's no issue with deleting bun as a dependency in package.json so this PR can be closed in favor of yours.

Any core maintainer can give opinion on removing it?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just tried it on arm64 fedora and indeed the hash is different :/

65 changes: 65 additions & 0 deletions .nix/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{pkgs}: let
packageData = builtins.fromJSON (builtins.readFile ../package.json);

# Fetch dependencies (Network enabled, verified by hash)
bunDeps = pkgs.stdenv.mkDerivation {
pname = "hunk-deps";
inherit (packageData) version;
src = ../.;
dontCheckForBrokenSymlinks = true;
nativeBuildInputs = [pkgs.bun];
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = pkgs.lib.fileContents ./nix-deps-hash.txt;

buildPhase = ''
export HOME=$TMPDIR
bun install --frozen-lockfile --no-progress --ignore-scripts
'';

installPhase = ''
mkdir -p $out
cp -R node_modules $out/
'';
};
in
pkgs.stdenv.mkDerivation {
pname = "hunk";
inherit (packageData) version;
src = ../.;
dontStrip = true;

nativeBuildInputs = with pkgs; [
bun
bash
];

buildPhase = ''
runHook preBuild

# Copy the pre-fetched dependencies
cp -R ${bunDeps}/node_modules ./node_modules
chmod -R +w ./node_modules

# Use project's custom build script
bun run build:bin

runHook postBuild
'';

installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp ./dist/hunk $out/bin/hunk
chmod +x $out/bin/hunk
runHook postInstall
'';

meta = with pkgs.lib; {
description = "Terminal diff viewer for agentic changesets";
homepage = "https://github.com/modem-dev/hunk";
license = licenses.mit;
mainProgram = "hunk";
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
};
}
43 changes: 43 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
description = "Hunk - Review-first terminal diff viewer for agentic coders";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
systems.url = "github:nix-systems/default";
};

outputs = {
systems,
nixpkgs,
...
}: let
eachSystem = nixpkgs.lib.genAttrs (import systems);
in {
packages = eachSystem (
system: let
pkgs = import nixpkgs {inherit system;};
in {
default = import ./.nix/package.nix {inherit pkgs;};
}
);
devShells = eachSystem (
system: let
pkgs = import nixpkgs {inherit system;};
in {
default = pkgs.mkShell {
buildInputs = with pkgs; [
bun
nodejs
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also nodejs is not needed in the devShell I think -- even though it's listed as a requirement in CONTRIBUTING.md. Not sure why it is. Git should always be installed but could be added to the devShell as to be explicit.

Copy link
Copy Markdown
Author

@emrtnn emrtnn May 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for the comment! Yeah indeed I tried yesterday to build it using bun2nix but adding the postinstall script gave me a lot of issues because this repo uses bun as a dependency itself so it was causing a conflict between the nix installed bun and the repo installed bun by the nix one. Since I couldn't manage solve this I chose this way.

image

Didn't know you were also working on this if I had I wouldn't have made this PR, that's why I opened #215 before anything.

That said, if you agree with following with this PR I consider your postinstall suggestion a really good catch and will be happy to add it. The only issue I see is that it will make installing deps much slower but maybe that's not that big of a deal for core contributors

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's very cool how we took two different routes and both landed at a valid solution to the problem! I too ran into the issue with the bun dependency in package.json. However, I just removed it there xd

git
];
};
}
);
};
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"bench:bootstrap-load": "bun run benchmarks/bootstrap-load.ts",
"bench:highlight-prefetch": "bun run benchmarks/highlight-prefetch.ts",
"bench:large-stream": "bun run benchmarks/large-stream.ts",
"bench:large-stream-profile": "bun run benchmarks/large-stream-profile.ts"
"bench:large-stream-profile": "bun run benchmarks/large-stream-profile.ts",
"nix:update-hash": "bash ./scripts/update-nix-hash.sh"
},
"dependencies": {
"@pierre/diffs": "^1.1.19",
Expand Down
19 changes: 19 additions & 0 deletions scripts/update-nix-hash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e

echo "Resetting Nix dependency hash..."
echo "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" >.nix/nix-deps-hash.txt

echo "Running Nix build to calculate new hash (this will intentionally fail)..."
OUTPUT=$(nix build 2>&1 || true)
NEW_HASH=$(echo "$OUTPUT" | grep -oE 'got:[[:space:]]+sha256-[a-zA-Z0-9+/=]+' | sed 's/got:[[:space:]]*//')

if [ -n "$NEW_HASH" ]; then
echo "$NEW_HASH" >.nix/nix-deps-hash.txt
echo "✅ Successfully updated .nix/nix-deps-hash.txt to: $NEW_HASH"
else
echo "❌ Failed to extract hash. Did the build succeed unexpectedly?"
echo "Nix output:"
echo "$OUTPUT"
exit 1
fi
Loading