Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
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.12.4"; 20 21 src = fetchFromGitHub { 22 owner = "astral-sh"; 23 repo = "ruff"; 24 tag = finalAttrs.version; 25 hash = "sha256-XuHVKxzXYlm3iEhdAVCyd62uNyb3jeJRl3B0hnvUzX0="; 26 }; 27 28 cargoBuildFlags = [ "--package=ruff" ]; 29 30 cargoHash = "sha256-cyjaGI7JoreAmHtUrRKNyiCaE8zveP/dFJROC2iIXr4="; 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_test" 70 "--exclude=ty_vendored" 71 "--exclude=ty_wasm" 72 ]; 73 74 nativeInstallCheckInputs = [ 75 versionCheckHook 76 ]; 77 versionCheckProgramArg = "--version"; 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 updateScript = nix-update-script { }; 85 }; 86 87 meta = { 88 description = "Extremely fast Python linter and code formatter"; 89 homepage = "https://github.com/astral-sh/ruff"; 90 changelog = "https://github.com/astral-sh/ruff/releases/tag/${finalAttrs.version}"; 91 license = lib.licenses.mit; 92 mainProgram = "ruff"; 93 maintainers = with lib.maintainers; [ 94 bengsparks 95 figsoda 96 GaetanLepage 97 ]; 98 }; 99})