Skip to content

Commit d6ed06f

Browse files
authored
feat(nix): add package validation and pinned lock regeneration (#284)
1 parent e9ba014 commit d6ed06f

10 files changed

Lines changed: 141 additions & 44 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ jobs:
3838
- name: Install dependencies
3939
run: bun install --frozen-lockfile
4040

41-
- name: Verify Nix lockfile is up to date
42-
run: |
43-
bun run nix:update-lock
44-
if ! git diff --exit-code nix/bun.lock.nix; then
45-
echo "::error::Nix lockfile is out of date. Please run 'bun run nix:update-lock' and commit the changes to nix/bun.lock.nix."
46-
exit 1
47-
fi
48-
4941
- name: Format check
5042
run: bun run format:check
5143

.github/workflows/nix.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Nix
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- "**/*.md"
7+
- "docs/**"
8+
- "assets/**"
9+
- "LICENSE"
10+
push:
11+
branches:
12+
- main
13+
paths-ignore:
14+
- "**/*.md"
15+
- "docs/**"
16+
- "assets/**"
17+
- "LICENSE"
18+
19+
concurrency:
20+
group: nix-${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
package:
25+
name: Package
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Check out repository
29+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
30+
31+
- name: Install Nix
32+
uses: cachix/install-nix-action@8aa03977d8d733052d78f4e008a241fd1dbf36b3 # v31.10.6
33+
with:
34+
extra_nix_config: |
35+
extra-trusted-substituters = https://nix-community.cachix.org
36+
extra-trusted-public-keys = nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=
37+
38+
- name: Verify Nix dependency lockfile
39+
run: |
40+
nix run .#update-bun-lock
41+
if ! git diff --exit-code nix/bun.lock.nix; then
42+
echo "::error::Nix lockfile is out of date. Please run 'bun run nix:update-lock' and commit the changes to nix/bun.lock.nix."
43+
exit 1
44+
fi
45+
46+
- name: Check flake outputs
47+
run: nix flake check --print-build-logs
48+
49+
- name: Evaluate all supported systems
50+
run: nix flake check --all-systems --no-build
51+
52+
- name: Build Hunk package
53+
run: nix build .#default --print-build-logs
54+
55+
- name: Smoke test Nix package
56+
run: |
57+
./result/bin/hunk --version
58+
skill_path="$(./result/bin/hunk skill path)"
59+
test -f "$skill_path"

.github/workflows/pr-ci.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,6 @@ jobs:
8181
- name: Install dependencies
8282
run: bun install --frozen-lockfile
8383

84-
- name: Verify Nix lockfile is up to date
85-
run: |
86-
bun run nix:update-lock
87-
if ! git diff --exit-code nix/bun.lock.nix; then
88-
echo "::error::Nix lockfile is out of date. Please run 'bun run nix:update-lock' and commit the changes to nix/bun.lock.nix."
89-
exit 1
90-
fi
91-
9284
- name: Format check
9385
run: bun run format:check
9486

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable user-visible changes to Hunk are documented in this file.
77
### Added
88

99
- Added Windows x64 prebuilt artifact publishing to the release workflow.
10+
- Added Nix flake app outputs for `nix run` and a named `hunk` package output.
1011

1112
### Changed
1213

CONTRIBUTING.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,24 @@ bun run check:prebuilt-pack
8787
bun run publish:prebuilt:npm -- --dry-run
8888
```
8989

90+
## Updating dependencies
91+
92+
After changing JavaScript or Bun dependencies, regenerate the Nix dependency lockfile so CI stays green:
93+
94+
```bash
95+
bun install
96+
bun run nix:update-lock
97+
git add bun.lock nix/bun.lock.nix package.json
98+
```
99+
100+
The `nix:update-lock` script requires a one-time [Nix install](https://nixos.org/download/):
101+
102+
```bash
103+
curl -L https://nixos.org/nix/install | sh
104+
```
105+
106+
If you don't have Nix installed, CI will catch the drift and a maintainer can push the regenerated lockfile as a follow-up commit.
107+
90108
## Validation expectations
91109

92110
- Rendering changes: run `bun run typecheck`, `bun test`, `bun run test:tty-smoke`, and do one real TTY smoke run on an actual diff.

bun.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,48 @@
2727
"aarch64-darwin"
2828
];
2929
forAllSystems = lib.genAttrs supportedSystems;
30-
in {
31-
packages = forAllSystems (
30+
perSystem = forAllSystems (
3231
system: let
3332
pkgs = import nixpkgs {
3433
inherit system;
3534
};
36-
in {
37-
default = pkgs.callPackage ./nix/package.nix {
35+
hunk = pkgs.callPackage ./nix/package.nix {
3836
bun2nix = bun2nix.packages.${system}.default;
3937
};
40-
}
41-
);
42-
43-
devShells = forAllSystems (
44-
system: let
45-
pkgs = import nixpkgs {
46-
inherit system;
47-
};
38+
updateBunLock = pkgs.writeShellScriptBin "hunk-update-bun-lock" ''
39+
set -euo pipefail
40+
${bun2nix.packages.${system}.default}/bin/bun2nix -o nix/bun.lock.nix -c ../ "$@"
41+
if [ -s nix/bun.lock.nix ] && [ "$(${pkgs.coreutils}/bin/tail -c 1 nix/bun.lock.nix)" != "" ]; then
42+
printf '\n' >> nix/bun.lock.nix
43+
fi
44+
'';
4845
in {
49-
default = pkgs.callPackage ./nix/devShell.nix {};
46+
packages = {
47+
inherit hunk;
48+
default = hunk;
49+
};
50+
apps = {
51+
default = {
52+
type = "app";
53+
program = "${hunk}/bin/hunk";
54+
meta.description = "Run Hunk";
55+
};
56+
update-bun-lock = {
57+
type = "app";
58+
program = "${updateBunLock}/bin/hunk-update-bun-lock";
59+
meta.description = "Regenerate nix/bun.lock.nix with the flake-pinned bun2nix";
60+
};
61+
};
62+
devShells = {
63+
default = pkgs.callPackage ./nix/devShell.nix {};
64+
};
5065
}
5166
);
67+
systemOutput = name: lib.mapAttrs (_: value: value.${name}) perSystem;
68+
in {
69+
packages = systemOutput "packages";
70+
apps = systemOutput "apps";
71+
devShells = systemOutput "devShells";
5272

5373
homeManagerModules = {
5474
hunk = import ./nix/home-manager.nix;

nix/README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Nix users can install Hunk from source instead of using npm.
2222
```nix
2323
{
2424
environment.systemPackages = [
25-
inputs.hunk.packages.${pkgs.stdenv.hostPlatform.system}.default
25+
inputs.hunk.packages.${pkgs.stdenv.hostPlatform.system}.hunk
2626
];
2727
}
2828
```
@@ -32,7 +32,7 @@ Or in Home Manager `home.packages`:
3232
```nix
3333
{
3434
home.packages = [
35-
inputs.hunk.packages.${pkgs.stdenv.hostPlatform.system}.default
35+
inputs.hunk.packages.${pkgs.stdenv.hostPlatform.system}.hunk
3636
];
3737
}
3838
```
@@ -63,6 +63,14 @@ Hunk provides a Home Manager module to manage both the package and its configura
6363

6464
`enableGitIntegration` writes to Home Manager's Git configuration, so it requires Home Manager's Git module to be enabled with `programs.git.enable = true;`.
6565

66+
## Running from a flake
67+
68+
Run Hunk directly with Nix:
69+
70+
```bash
71+
nix run github:modem-dev/hunk -- --help
72+
```
73+
6674
## Updating Hunk
6775

6876
Flake users update Hunk by updating their own pinned `flake.lock` input:
@@ -73,8 +81,13 @@ nix flake lock --update-input hunk
7381

7482
## Building using Nix
7583

76-
Simply run `nix build .#packages.{YOUR_SYSTEM}.default` where YOUR_SYSTEM is one of `x86_64-linux`, `x86_64-darwin`, `aarch64-linux` or `aarch64-darwin`. The resulting
77-
Hunk binary will be `./result/bin/hunk`.
84+
Run `nix build` to build the default package for the current system. The resulting Hunk binary will be `./result/bin/hunk`.
85+
86+
You can also build the named package explicitly:
87+
88+
```bash
89+
nix build .#hunk
90+
```
7891

7992
## Maintainer dependency updates
8093

@@ -83,3 +96,5 @@ When JavaScript or Bun dependencies change, regenerate the Nix dependency lockfi
8396
```bash
8497
bun run nix:update-lock
8598
```
99+
100+
This script requires Nix and runs the flake-pinned `bun2nix` version from `flake.lock`.

nix/bun.lock.nix

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,9 @@
453453
url = "https://registry.npmjs.org/@tokenizer/token/-/token-0.3.0.tgz";
454454
hash = "sha512-OvjF+z51L3ov0OyAU0duzsYuvO01PH7x4t6DJx+guahgTnBHkhJdG7soQeTSFLWN3efnHyibZ4Z8l2EuWwJN3A==";
455455
};
456-
"@types/bun@1.3.10" = fetchurl {
457-
url = "https://registry.npmjs.org/@types/bun/-/bun-1.3.10.tgz";
458-
hash = "sha512-0+rlrUrOrTSskibryHbvQkDOWRJwJZqZlxrUs1u4oOoTln8+WIXBPmAuCF35SWB2z4Zl3E84Nl/D0P7803nigQ==";
456+
"@types/bun@1.3.13" = fetchurl {
457+
url = "https://registry.npmjs.org/@types/bun/-/bun-1.3.13.tgz";
458+
hash = "sha512-9fqXWk5YIHGGnUau9TEi+qdlTYDAnOj+xLCmSTwXfAIqXr2x4tytJb43E9uCvt09zJURKXwAtkoH4nLQfzeTXw==";
459459
};
460460
"@types/hast@3.0.4" = fetchurl {
461461
url = "https://registry.npmjs.org/@types/hast/-/hast-3.0.4.tgz";
@@ -533,9 +533,9 @@
533533
url = "https://registry.npmjs.org/bun-ffi-structs/-/bun-ffi-structs-0.1.2.tgz";
534534
hash = "sha512-Lh1oQAYHDcnesJauieA4UNkWGXY9hYck7OA5IaRwE3Bp6K2F2pJSNYqq+hIy7P3uOvo3km3oxS8304g5gDMl/w==";
535535
};
536-
"bun-types@1.3.10" = fetchurl {
537-
url = "https://registry.npmjs.org/bun-types/-/bun-types-1.3.10.tgz";
538-
hash = "sha512-tcpfCCl6XWo6nCVnpcVrxQ+9AYN1iqMIzgrSKYMB/fjLtV2eyAVEg7AxQJuCq/26R6HpKWykQXuSOq/21RYcbg==";
536+
"bun-types@1.3.13" = fetchurl {
537+
url = "https://registry.npmjs.org/bun-types/-/bun-types-1.3.13.tgz";
538+
hash = "sha512-QXKeHLlOLqQX9LgYaHJfzdBaV21T63HhFJnvuRCcjZiaUDpbs5ED1MgxbMra71CsryN/1dAoXuJJJwIv/2drVA==";
539539
};
540540
"bun-webgpu-darwin-arm64@0.1.5" = fetchurl {
541541
url = "https://registry.npmjs.org/bun-webgpu-darwin-arm64/-/bun-webgpu-darwin-arm64-0.1.5.tgz";

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"bench:highlight-prefetch": "bun run benchmarks/highlight-prefetch.ts",
7272
"bench:large-stream": "bun run benchmarks/large-stream.ts",
7373
"bench:large-stream-profile": "bun run benchmarks/large-stream-profile.ts",
74-
"nix:update-lock": "bunx bun2nix -o nix/bun.lock.nix -c ../"
74+
"nix:update-lock": "nix run .#update-bun-lock"
7575
},
7676
"dependencies": {
7777
"@pierre/diffs": "^1.1.19",
@@ -87,7 +87,7 @@
8787
"@hunk/session-broker-node": "workspace:*",
8888
"@opentui/core": "^0.1.88",
8989
"@opentui/react": "^0.1.88",
90-
"@types/bun": "latest",
90+
"@types/bun": "1.3.13",
9191
"@types/react": "^19.2.14",
9292
"@types/ws": "^8.18.1",
9393
"lint-staged": "^16.4.0",

0 commit comments

Comments
 (0)