From 81aeff6b4e7110c933e9c54530e64aa6e760e12f Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 7 Aug 2026 09:37:40 +0000 Subject: [PATCH] nix: add ruff.nix (v16.0.1) --- nix/ruff.nix | 75 +++++++++++++++++++++++++++++++++++++++++++ nix/user-packages.nix | 2 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 nix/ruff.nix diff --git a/nix/ruff.nix b/nix/ruff.nix new file mode 100644 index 00000000..025b6868 --- /dev/null +++ b/nix/ruff.nix @@ -0,0 +1,75 @@ +{ + lib, + stdenv, + rustPlatform, + fetchFromGitHub, + installShellFiles, + + rust-jemalloc-sys, + buildPackages, + versionCheckHook, + + nixosTests, +}: + +rustPlatform.buildRustPackage rec { + pname = "ruff"; + version = "0.16.1"; + + __structuredAttrs = true; + + src = fetchFromGitHub { + owner = "astral-sh"; + repo = "ruff"; + tag = version; + hash = "sha256-77h1f8LV9ZTYqs5SymLij6CXe3TzrXEMcCPASOHj/UU="; + }; + + cargoBuildFlags = [ "--package=ruff" ]; + + cargoHash = "sha256-fgcl0JhGkzbXD+ajDdIwnIUHEuKj3XwDH81JkDEqntc="; + + nativeBuildInputs = [ installShellFiles ]; + + buildInputs = [ rust-jemalloc-sys ]; + + # Run cargo tests + checkType = "debug"; + + # tests do not appear to respect linker options on doctests + # Upstream issue: https://github.com/rust-lang/cargo/issues/14189 + # This causes errors like "error: linker `cc` not found" on static builds + doCheck = !stdenv.hostPlatform.isStatic; + + # Exclude tests from `ty`-related crates, run everything else. + # Ordinarily we would run all the tests, but there is significant overlap with the `ty` package in nixpkgs, + # which ruff shares a monorepo with. + # As such, we leave running `ty` tests to the `ty` package, and concentrate on everything else. + cargoTestFlags = [ + "--workspace" + "--exclude=ty" + "--exclude=ty_ide" + "--exclude=ty_project" + "--exclude=ty_python_semantic" + "--exclude=ty_server" + "--exclude=ty_static" + "--exclude=ty_test" + "--exclude=ty_vendored" + "--exclude=ty_wasm" + ]; + + nativeInstallCheckInputs = [ versionCheckHook ]; + doInstallCheck = true; + + meta = { + description = "Extremely fast Python linter and code formatter"; + homepage = "https://github.com/astral-sh/ruff"; + changelog = "https://github.com/astral-sh/ruff/releases/tag/${version}"; + license = lib.licenses.mit; + mainProgram = "ruff"; + maintainers = with lib.maintainers; [ + bengsparks + GaetanLepage + ]; + }; +} diff --git a/nix/user-packages.nix b/nix/user-packages.nix index 78b7997e..b8016e8a 100644 --- a/nix/user-packages.nix +++ b/nix/user-packages.nix @@ -30,7 +30,7 @@ rec { # which = which; # ctags = universal-ctags; # xclip = xclip; - # ruff = ruff; + # ruff = callPackage (bdir + /ruff.nix) {}; # perl = perl; # netcat = netcat-openbsd; # jq = jq;