From 2c2e93e6f562cd1a62d4b696a1d7d54f3d6fb423 Mon Sep 17 00:00:00 2001 From: ReStranger Date: Tue, 20 Oct 2026 22:39:52 +0300 Subject: [PATCH] feat(nix): package Biome 2.3.5 and integrate with treefmt and devshell --- flake.nix | 7 ++++--- nix/biome.nix | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ nix/devshell.nix | 5 +++++ nix/treefmt.nix | 20 ++++--------------- 4 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 nix/biome.nix diff --git a/flake.nix b/flake.nix index 112e0c29a..aa9c624cc 100644 --- a/flake.nix +++ b/flake.nix @@ -36,6 +36,7 @@ forAllSystems = genAttrs platforms; piOverlay = _final: prev: { + biome = prev.callPackage ./nix/biome.nix { }; pi = prev.callPackage ./nix/package.nix { inherit source packageJson platforms; nodejs = prev.nodejs_22; @@ -45,9 +46,9 @@ perSystem = system: let - pkgs = nixpkgsFor system; - pi = (pkgs.extend piOverlay).pi; - treefmtWrapper = import ./nix/treefmt.nix { inherit pkgs source; }; + pkgs = (nixpkgsFor system).extend piOverlay; + inherit (pkgs) pi; + treefmtWrapper = import ./nix/treefmt.nix { inherit pkgs; }; devShell = import ./nix/devshell.nix { inherit pkgs treefmtWrapper; nodejs = pkgs.nodejs_22; diff --git a/nix/biome.nix b/nix/biome.nix new file mode 100644 index 000000000..bdb318a5d --- /dev/null +++ b/nix/biome.nix @@ -0,0 +1,50 @@ +{ + lib, + stdenv, + fetchurl, + autoPatchelfHook, +}: +stdenv.mkDerivation (finalAttrs: { + pname = "biome"; + version = "2.3.5"; + + src = + finalAttrs.passthru.sources.${stdenv.hostPlatform.system} + or (throw "Unsupported system for Biome: ${stdenv.hostPlatform.system}"); + + nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ]; + buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ stdenv.cc.cc.lib ]; + + installPhase = '' + runHook preInstall + install -Dm755 biome $out/bin/biome + runHook postInstall + ''; + + passthru.sources = { + x86_64-linux = fetchurl { + url = "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-${finalAttrs.version}.tgz"; + hash = "sha256-2k7rG5YgEyMtJ7jAI+JWPzWhdxlNZI6TqyMVngU9Dus="; + }; + aarch64-linux = fetchurl { + url = "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-${finalAttrs.version}.tgz"; + hash = "sha256-cLKXQ7uIyS2aQ7P95IHh7A7hI7z89p8WUKeYW3/4N/I="; + }; + x86_64-darwin = fetchurl { + url = "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-${finalAttrs.version}.tgz"; + hash = "sha256-cD7JJVxSXEAQnYSgWAbOC1EPJ+M0+q7h0xg57OXao4o="; + }; + aarch64-darwin = fetchurl { + url = "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-${finalAttrs.version}.tgz"; + hash = "sha256-sMi2Aywy3UnD9hQPyroTMPfCsFSZKRqqnb8uC5oNX34="; + }; + }; + + meta = { + description = "Toolchain of the web"; + homepage = "https://biomejs.dev/"; + license = lib.licenses.mit; + platforms = builtins.attrNames finalAttrs.passthru.sources; + mainProgram = finalAttrs.pname; + }; +}) diff --git a/nix/devshell.nix b/nix/devshell.nix index 90361acff..7c3ea80f9 100644 --- a/nix/devshell.nix +++ b/nix/devshell.nix @@ -3,14 +3,19 @@ nodejs, treefmtWrapper, }: +let + inherit (pkgs.lib) getExe; +in pkgs.mkShell { packages = [ nodejs pkgs.git + pkgs.biome treefmtWrapper ]; shellHook = '' + export BIOME_BINARY="${getExe pkgs.biome}" git config core.hooksPath .husky ''; } diff --git a/nix/treefmt.nix b/nix/treefmt.nix index 790b93b8f..7b51549cc 100644 --- a/nix/treefmt.nix +++ b/nix/treefmt.nix @@ -1,18 +1,8 @@ -{ pkgs, source }: -let - biomeConfig = pkgs.writeText "biome.json" ( - builtins.toJSON ( - (pkgs.lib.importJSON "${source}/biome.json") - // { - plugins = [ "${source}/scripts/biome/model-type-comparison.grit" ]; - } - ) - ); -in +{ pkgs }: pkgs.treefmt.withConfig { - runtimeInputs = [ - pkgs.biome - pkgs.nixfmt + runtimeInputs = with pkgs; [ + biome + nixfmt ]; settings = { global.tree_root_file = "flake.nix"; @@ -23,8 +13,6 @@ pkgs.treefmt.withConfig { "format" "--write" "--no-errors-on-unmatched" - "--config-path" - (builtins.toString biomeConfig) ]; includes = [ "*.cjs"