diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9bf2d9..1519feb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,4 +25,4 @@ jobs: bun-version: "1.4.2" - run: bun install --frozen-lockfile - run: bun run check - - run: npm pack --dry-run + - run: bun pm pack --dry-run diff --git a/.gitignore b/.gitignore index dc5ffe0..e47156f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ coverage/ .DS_Store *.log .claude/ +.direnv/ +.pre-commit-config.yaml diff --git a/.zed/settings.json b/.zed/settings.json new file mode 100644 index 0000000..28e4782 --- /dev/null +++ b/.zed/settings.json @@ -0,0 +1,45 @@ +{ + "format_on_save": "on", + "lsp": { + "biome": { + "settings": { + "require_config_file": true + } + }, + "nil": { + "binary": { + "path": "direnv", + "arguments": ["exec", ".", "nil"] + } + } + }, + "languages": { + "JavaScript": { + "formatter": { "language_server": { "name": "biome" } }, + "code_actions_on_format": { + "source.organizeImports.biome": true + } + }, + "TypeScript": { + "formatter": { "language_server": { "name": "biome" } }, + "code_actions_on_format": { + "source.organizeImports.biome": true + } + }, + "JSON": { + "formatter": { "language_server": { "name": "biome" } } + }, + "JSONC": { + "formatter": { "language_server": { "name": "biome" } } + }, + "Nix": { + "language_servers": ["nil", "!nixd"], + "formatter": { + "external": { + "command": "direnv", + "arguments": ["exec", ".", "nixfmt", "-"] + } + } + } + } +} diff --git a/README.md b/README.md index 7b00846..a735af7 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,9 @@ gets**. ## Development -You need Bun 1.4.2, Python 3 and macOS or Linux. +You need Bun 1.4.2, Python 3 and macOS or Linux. [Nix](https://nixos.org) +gives the shell all three, and lints each commit with Biome and nixfmt: +`nix develop`, or `direnv allow` once. ```sh bun install --frozen-lockfile diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..69add14 --- /dev/null +++ b/flake.lock @@ -0,0 +1,82 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "flake-compat", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1791909798, + "narHash": "sha256-VAhpCOmrun/KXimYfR8NM88bciKCui7CqHHhThSzgag=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "1ba1dbfe28738c9a71c266be6efa5b89e75491a9", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1791765022, + "narHash": "sha256-ZGq3ptZzA+oO0N/Wi/F+GbuTijLkYExD01LvpNFAvr0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7993f34ee47e28a3d607a525aadc6c94b73be728", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-26.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1791734076, + "narHash": "sha256-i5qk1kLiit98rRbh1AXmWBNT9QXC/y4l5Wk/u5EdpDQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7fd4004d0511991fff3a0524856a9be09e28c5f0", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "git-hooks": "git-hooks", + "nixpkgs": "nixpkgs", + "nixpkgs-unstable": "nixpkgs-unstable" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..c50529e --- /dev/null +++ b/flake.nix @@ -0,0 +1,69 @@ +{ + description = "The Leverage plugin for Pi: its development shell"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05"; + # Only for Bun: stable has 1.3.13, and the project pins 1.4.2. + nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; + git-hooks.url = "github:cachix/git-hooks.nix"; + git-hooks.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = + { + nixpkgs, + nixpkgs-unstable, + git-hooks, + ... + }: + let + systems = [ + "aarch64-darwin" + "x86_64-darwin" + "aarch64-linux" + "x86_64-linux" + ]; + forEach = f: nixpkgs.lib.genAttrs systems (system: f system nixpkgs.legacyPackages.${system}); + # Lints each commit once the shell is entered. + hooks = forEach ( + system: pkgs: + git-hooks.lib.${system}.run { + src = ./.; + hooks = { + # The project's own Biome, the version CI checks with. + biome = { + enable = true; + name = "biome"; + entry = "node_modules/.bin/biome check --write --no-errors-on-unmatched --files-ignore-unknown=true"; + types_or = [ + "javascript" + "jsx" + "ts" + "tsx" + "json" + ]; + }; + nixfmt.enable = true; + }; + } + ); + in + { + devShells = forEach ( + system: pkgs: { + default = pkgs.mkShell { + inherit (hooks.${system}) shellHook; + packages = [ + nixpkgs-unstable.legacyPackages.${system}.bun + pkgs.nodejs_24 + # The tests drive real terminals through Python. + pkgs.python3 + # Zed's language server for flake.nix. + pkgs.nil + ] + ++ hooks.${system}.enabledPackages; + }; + } + ); + }; +}