nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 rustPlatform,
5 fetchFromGitHub,
6 installShellFiles,
7
8 rust-jemalloc-sys,
9 buildPackages,
10 versionCheckHook,
11
12 # passthru
13 nixosTests,
14 nix-update-script,
15}:
16
17rustPlatform.buildRustPackage (finalAttrs: {
18 pname = "ruff";
19 version = "0.14.14";
20
21 src = fetchFromGitHub {
22 owner = "astral-sh";
23 repo = "ruff";
24 tag = finalAttrs.version;
25 hash = "sha256-h6XYWK6NxelLCfqG0geiAj3XbcqzbeFKeFMMDsy8fm8=";
26 };
27
28 cargoBuildFlags = [ "--package=ruff" ];
29
30 cargoHash = "sha256-H5ZaBDV0YTdExu42Dt1Bq379vJ3FtddKtdLkMW+qC78=";
31
32 nativeBuildInputs = [ installShellFiles ];
33
34 buildInputs = [
35 rust-jemalloc-sys
36 ];
37
38 postInstall = lib.optionalString (stdenv.hostPlatform.emulatorAvailable buildPackages) (
39 let
40 emulator = stdenv.hostPlatform.emulator buildPackages;
41 in
42 ''
43 installShellCompletion --cmd ruff \
44 --bash <(${emulator} $out/bin/ruff generate-shell-completion bash) \
45 --fish <(${emulator} $out/bin/ruff generate-shell-completion fish) \
46 --zsh <(${emulator} $out/bin/ruff generate-shell-completion zsh)
47 ''
48 );
49
50 # Run cargo tests
51 checkType = "debug";
52
53 # tests do not appear to respect linker options on doctests
54 # Upstream issue: https://github.com/rust-lang/cargo/issues/14189
55 # This causes errors like "error: linker `cc` not found" on static builds
56 doCheck = !stdenv.hostPlatform.isStatic;
57
58 # Exclude tests from `ty`-related crates, run everything else.
59 # Ordinarily we would run all the tests, but there is significant overlap with the `ty` package in nixpkgs,
60 # which ruff shares a monorepo with.
61 # As such, we leave running `ty` tests to the `ty` package, and concentrate on everything else.
62 cargoTestFlags = [
63 "--workspace"
64 "--exclude=ty"
65 "--exclude=ty_ide"
66 "--exclude=ty_project"
67 "--exclude=ty_python_semantic"
68 "--exclude=ty_server"
69 "--exclude=ty_static"
70 "--exclude=ty_test"
71 "--exclude=ty_vendored"
72 "--exclude=ty_wasm"
73 ];
74
75 nativeInstallCheckInputs = [
76 versionCheckHook
77 ];
78 doInstallCheck = true;
79
80 passthru = {
81 tests = lib.optionalAttrs stdenv.hostPlatform.isLinux {
82 nixos-test-driver-busybox = nixosTests.nixos-test-driver.busybox;
83 };
84 # Updating `ruff` needs to be done on staging due to NixOS tests. Disabling r-ryantm update bot:
85 # nixpkgs-update: no auto update
86 updateScript = nix-update-script { };
87 };
88
89 meta = {
90 description = "Extremely fast Python linter and code formatter";
91 homepage = "https://github.com/astral-sh/ruff";
92 changelog = "https://github.com/astral-sh/ruff/releases/tag/${finalAttrs.version}";
93 license = lib.licenses.mit;
94 mainProgram = "ruff";
95 maintainers = with lib.maintainers; [
96 bengsparks
97 GaetanLepage
98 ];
99 };
100})