-
Notifications
You must be signed in to change notification settings - Fork 50
feat(nix): add flake to support nix builds #230
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ node_modules | |
| out | ||
| dist | ||
| *.tgz | ||
| result | ||
|
|
||
| # code coverage | ||
| coverage | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| sha256-Lr3M22JlMcX+HTZay2A1rN/zwGnznIjaib3E3y0Aob0= | ||
| 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" ]; | ||
| }; | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| git | ||
| ]; | ||
| }; | ||
| } | ||
| ); | ||
| }; | ||
| } | ||
| 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 |

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.
I think the hash might change across architectures (darwin/linux and x86/arm64). I can test this if needed
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.
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.jsonas 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
jsonfile with one hash per architecture instead of atxtone 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?
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.
just tried it on arm64 fedora and indeed the hash is different :/