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
26 changes: 25 additions & 1 deletion flake.lock

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

127 changes: 66 additions & 61 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
description = "Dev Flake for Modem-dev's Hunk";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
bun2nix.url = "github:nix-community/bun2nix";
bun2nix.inputs.nixpkgs.follows = "nixpkgs";
nixpkgs-lib.follows = "nixpkgs";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs-lib";
};
bun2nix = {
url = "github:nix-community/bun2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

nixConfig = {
extra-substituters = [
"https://nix-community.cachix.org"
Expand All @@ -13,69 +21,66 @@
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
};
outputs = {
self,
nixpkgs,
bun2nix,
...
}: let
lib = nixpkgs.lib;
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = lib.genAttrs supportedSystems;
perSystem = forAllSystems (
system: let
pkgs = import nixpkgs {
inherit system;
};
hunk = pkgs.callPackage ./nix/package.nix {
bun2nix = bun2nix.packages.${system}.default;
};
updateBunLock = pkgs.writeShellScriptBin "hunk-update-bun-lock" ''
set -euo pipefail
${bun2nix.packages.${system}.default}/bin/bun2nix -o nix/bun.lock.nix -c ../ "$@"
if [ -s nix/bun.lock.nix ] && [ "$(${pkgs.coreutils}/bin/tail -c 1 nix/bun.lock.nix)" != "" ]; then
printf '\n' >> nix/bun.lock.nix
fi
'';
in {
packages = {
inherit hunk;
default = hunk;
};
apps = {
default = {
type = "app";
program = "${hunk}/bin/hunk";
meta.description = "Run Hunk";

outputs =
{ flake-parts, bun2nix, ... }@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];

perSystem =
{ system, pkgs, ... }:
let
hunk = pkgs.callPackage ./nix/package.nix {
bun2nix = bun2nix.packages.${system}.default;
};
update-bun-lock = {
type = "app";
program = "${updateBunLock}/bin/hunk-update-bun-lock";
meta.description = "Regenerate nix/bun.lock.nix with the flake-pinned bun2nix";

updateBunLock = pkgs.writeShellScriptBin "hunk-update-bun-lock" ''
set -euo pipefail
${bun2nix.packages.${system}.default}/bin/bun2nix -o nix/bun.lock.nix -c ../ "$@"
if [ -s nix/bun.lock.nix ] && [ "$(${pkgs.coreutils}/bin/tail -c 1 nix/bun.lock.nix)" != "" ]; then
printf '\n' >> nix/bun.lock.nix
fi
'';
in
{
packages = {
inherit hunk;
default = hunk;
};

apps = {
default = {
type = "app";
program = "${hunk}/bin/hunk";
meta.description = "Run Hunk";
};

update-bun-lock = {
type = "app";
program = "${updateBunLock}/bin/hunk-update-bun-lock";
meta.description = "Regenerate nix/bun.lock.nix with the flake-pinned bun2nix";
};
};

devShells = {
default = pkgs.callPackage ./nix/devShell.nix { };
};
};
devShells = {
default = pkgs.callPackage ./nix/devShell.nix {};
};
}
);
systemOutput = name: lib.mapAttrs (_: value: value.${name}) perSystem;
in {
packages = systemOutput "packages";
apps = systemOutput "apps";
devShells = systemOutput "devShells";

homeManagerModules = {
hunk = import ./nix/home-manager.nix;
default = {pkgs, ...}: {
imports = [self.homeManagerModules.hunk];
programs.hunk.package = lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.default;
flake = {
homeManagerModules = {
hunk = import ./nix/home-manager.nix;
default = { pkgs, lib, ... }: {
imports = [ inputs.self.homeManagerModules.hunk ];
programs.hunk.package =
lib.mkDefault
inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.default;
};
};
};
};
};
}
81 changes: 43 additions & 38 deletions nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,54 @@
bun2nix,
lib,
...
}: let
}:
let
packageJson = lib.importJSON ../package.json;
in
bun2nix.mkDerivation {
pname = "hunkdiff";
version = packageJson.version;
bun2nix.mkDerivation {
pname = "hunkdiff";
version = packageJson.version;

src = ../.;
src = ../.;

bunDeps = bun2nix.fetchBunDeps {
bunNix = ./bun.lock.nix;
};
bunDeps = bun2nix.fetchBunDeps {
bunNix = ./bun.lock.nix;
};

buildPhase = ''
runHook preBuild
mkdir -p .bun-tmp .bun-install
BUN_TMPDIR=$PWD/.bun-tmp \
BUN_INSTALL=$PWD/.bun-install \
${bun}/bin/bun build --compile \
--no-compile-autoload-bunfig \
"./src/main.tsx" \
--outfile "hunk-bin"
runHook postBuild
'';
buildPhase = ''
runHook preBuild
mkdir -p .bun-tmp .bun-install
BUN_TMPDIR=$PWD/.bun-tmp \
BUN_INSTALL=$PWD/.bun-install \
${bun}/bin/bun build --compile \
--no-compile-autoload-bunfig \
"./src/main.tsx" \
--outfile "hunk-bin"
runHook postBuild
'';

installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp -p ./hunk-bin $out/bin/hunk
cp -r ./skills $out/
runHook postInstall
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp -p ./hunk-bin $out/bin/hunk
cp -r ./skills $out/
runHook postInstall
'';

# See https://nix-community.github.io/bun2nix/building-packages/hook.html#arguments for options
dontFixup = true;
dontStrip = true;
dontRunLifecycleScripts = true;
# See https://nix-community.github.io/bun2nix/building-packages/hook.html#arguments for options
dontFixup = true;
dontStrip = true;
dontRunLifecycleScripts = true;

meta = with 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" ];
};
}
meta = with 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"
"aarch64-darwin"
];
};
}
Loading