diff --git a/.gitignore b/.gitignore index 435882b3..63114e23 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,6 @@ test-languages/ nul release/ + +# Nix +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..7a7f0470 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "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": 1779414690, + "narHash": "sha256-gOTcX/9MZVMUE0Xvb4IEcv+0TQJkZFNEnL757ljU360=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6dedf69f94d03cbe7bdde106f2d4c23ae2a853bf", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "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 00000000..af3ae7bf --- /dev/null +++ b/flake.nix @@ -0,0 +1,85 @@ +{ + description = "CodeGraph – semantic code intelligence for AI agents"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + nodejs = pkgs.nodejs_24; + + codegraph = pkgs.buildNpmPackage { + pname = "codegraph"; + version = + (builtins.fromJSON (builtins.readFile ./package.json)).version; + + src = ./.; + + npmDeps = pkgs.fetchNpmDeps { + src = ./.; + hash = "sha256-GJfqzykgrgD/KCtf8LupRw31S2cCmwGCF/0PMpzaCrk="; + }; + + inherit nodejs; + + npmBuildScript = "build"; + + # The build copies .wasm + schema.sql into dist/ via the + # `copy-assets` npm script (called from `build`). Nothing + # extra to do here. + + installPhase = '' + runHook preInstall + + # Application code + mkdir -p $out/lib/codegraph + cp -r dist $out/lib/codegraph/dist + cp package.json $out/lib/codegraph/ + + # Production node_modules (already populated by buildNpmPackage) + cp -r node_modules $out/lib/codegraph/node_modules + + # Launcher wrapper: injects --liftoff-only so tree-sitter's + # large WASM grammars stay on V8's Liftoff baseline compiler + # and never hit the turboshaft Zone OOM (issues #293/#298). + mkdir -p $out/bin + cat > $out/bin/codegraph <<'EOF' +#!/bin/sh +exec @node@ --liftoff-only @out@/lib/codegraph/dist/bin/codegraph.js "$@" +EOF + substituteInPlace $out/bin/codegraph \ + --replace-fail '@node@' '${nodejs}/bin/node' \ + --replace-fail '@out@' "$out" + chmod +x $out/bin/codegraph + + runHook postInstall + ''; + + # No native addons to build — pure JS + WASM. + dontNpmBuild = false; + + meta = with pkgs.lib; { + description = + "Semantic code intelligence for AI agents — local-first knowledge graph over tree-sitter"; + homepage = "https://github.com/colbymchenry/codegraph"; + license = licenses.mit; + mainProgram = "codegraph"; + platforms = platforms.unix; + }; + }; + in { + packages = { + default = codegraph; + inherit codegraph; + }; + + devShells.default = pkgs.mkShell { + buildInputs = [ nodejs ]; + }; + }); +}