From 614037f28411a819d3a5c289d90a07d6db260b8c Mon Sep 17 00:00:00 2001 From: Bruce Arctor <5032356+brucearctor@users.noreply.github.com> Date: Sun, 12 Jul 2026 18:49:27 -0700 Subject: [PATCH] chore: add nix dev shell, lefthook, and direnv - flake.nix: pins Node 22, pnpm, Python 3.13, buf, lefthook, and common tools - lefthook.yml: pre-commit (nix-fmt, ts-lint, ts-fmt) and pre-push (build, test) - .envrc: direnv integration for automatic shell activation - .gitignore: add result/ and .direnv/ Closes #34 --- .envrc | 3 +++ .gitignore | 6 +++++- flake.lock | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ lefthook.yml | 41 +++++++++++++++++++++++++++++++++++ 5 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 lefthook.yml diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..993bf04 --- /dev/null +++ b/.envrc @@ -0,0 +1,3 @@ +# Auto-activate the nix dev shell via direnv +# Install direnv + nix-direnv for seamless shell activation +use flake diff --git a/.gitignore b/.gitignore index f76c24f..b70cff6 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,8 @@ npm-debug.log *.DS_store ./site/_site .jekyll-cache -pnpm-lock.yaml \ No newline at end of file +pnpm-lock.yaml + +# Nix / direnv +result +.direnv/ \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a8f8b83 --- /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": 1783816212, + "narHash": "sha256-2aZisVTVGSFEk3MYcOiWQp3zvwyzbqpktB69Rcfp150=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3b32825de172d0bc85664f495edb096b10862524", + "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 0000000..fae7c8d --- /dev/null +++ b/flake.nix @@ -0,0 +1,58 @@ +{ + description = "Apache Flagon — behavioral analytics monorepo"; + + 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}; + in + { + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + # Node / TypeScript (UserALE.js) + nodejs_24 + pnpm + typescript + + # Python (Distill) + python313 + uv + + # Pre-commit hooks + lefthook + + # Protobuf (schema codegen — future use) + buf + + # Tools + git + jq + curl + nixpkgs-fmt + ]; + + shellHook = '' + echo "🔥 Apache Flagon dev shell" + echo " node: $(node --version)" + echo " pnpm: $(pnpm --version)" + echo " tsc: $(tsc --version)" + echo " python: $(python3 --version)" + echo " buf: $(buf --version 2>&1 | head -1)" + echo "" + + # Install lefthook git hooks on first entry + if [ ! -f .git/hooks/pre-commit ] || ! grep -q lefthook .git/hooks/pre-commit 2>/dev/null; then + echo "Installing lefthook git hooks..." + lefthook install + fi + + echo "Run 'pnpm install' in products/userale to get started" + ''; + }; + }); +} diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 0000000..c45d713 --- /dev/null +++ b/lefthook.yml @@ -0,0 +1,41 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +pre-commit: + parallel: true + commands: + nix-fmt: + glob: "*.nix" + run: nixpkgs-fmt {staged_files} + ts-lint: + glob: "*.{ts,tsx}" + root: "products/userale/" + run: pnpm eslint {staged_files} + ts-fmt: + glob: "*.{ts,tsx,js,jsx,json,css,md}" + root: "products/userale/" + run: pnpm prettier --check {staged_files} + +pre-push: + parallel: false + commands: + userale-build: + root: "products/userale/packages/flagon-userale/" + run: npx tsup --onSuccess 'tsc --emitDeclarationOnly --declaration' + userale-test: + root: "products/userale/packages/flagon-userale/" + run: npx jest -c ./test/jest.config.ts