Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at flake-libs 168 lines 4.6 kB view raw
1{ 2 stdenv, 3 lib, 4 runCommand, 5 patchelf, 6 fetchFromGitHub, 7 rustPlatform, 8 makeBinaryWrapper, 9 pkg-config, 10 openssl, 11 curl, 12 writableTmpDirAsHomeHook, 13 installShellFiles, 14 zlib, 15 libiconv, 16 xz, 17 buildPackages, 18}: 19 20let 21 libPath = lib.makeLibraryPath [ 22 zlib # libz.so.1 23 ]; 24in 25 26rustPlatform.buildRustPackage (finalAttrs: { 27 pname = "rustup"; 28 version = "1.28.2"; 29 30 src = fetchFromGitHub { 31 owner = "rust-lang"; 32 repo = "rustup"; 33 tag = finalAttrs.version; 34 hash = "sha256-iX5hEaQwCW9MuyafjXml8jV3EDnxRNUlOoy3Cur/Iyw="; 35 }; 36 37 useFetchCargoVendor = true; 38 cargoHash = "sha256-KljaAzYHbny7KHOO51MotdmNpHCKWdt6kc/FIpFN6c0="; 39 40 nativeBuildInputs = [ 41 makeBinaryWrapper 42 pkg-config 43 writableTmpDirAsHomeHook 44 installShellFiles 45 ]; 46 47 buildInputs = 48 [ 49 openssl 50 curl 51 zlib 52 ] 53 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 54 libiconv 55 xz 56 ]; 57 58 buildFeatures = [ "no-self-update" ]; 59 60 checkFeatures = [ "test" ]; 61 62 patches = lib.optionals stdenv.hostPlatform.isLinux [ 63 (runCommand "0001-dynamically-patchelf-binaries.patch" 64 { 65 CC = stdenv.cc; 66 patchelf = patchelf; 67 libPath = "${libPath}"; 68 } 69 '' 70 export dynamicLinker=$(cat $CC/nix-support/dynamic-linker) 71 substitute ${./0001-dynamically-patchelf-binaries.patch} $out \ 72 --subst-var patchelf \ 73 --subst-var dynamicLinker \ 74 --subst-var libPath 75 '' 76 ) 77 ]; 78 79 # Random tests fail nondeterministically on macOS. 80 # TODO: Investigate this. 81 doCheck = !stdenv.hostPlatform.isDarwin; 82 # Random failures when running tests in parallel. 83 preCheck = '' 84 export NIX_BUILD_CORES=1 85 ''; 86 87 # skip failing tests 88 checkFlags = [ 89 # auto-self-update mode is set to 'disable' for nix rustup 90 "--skip=suite::cli_exact::check_updates_none" 91 "--skip=suite::cli_exact::check_updates_some" 92 "--skip=suite::cli_exact::check_updates_with_update" 93 # rustup-init is not used in nix rustup 94 "--skip=suite::cli_ui::rustup_init_ui_doc_text_tests" 95 ]; 96 97 postInstall = '' 98 pushd $out/bin 99 mv rustup-init rustup 100 binlinks=( 101 cargo rustc rustdoc rust-gdb rust-lldb rls rustfmt cargo-fmt 102 cargo-clippy clippy-driver cargo-miri rust-gdbgui rust-analyzer 103 ) 104 for link in ''${binlinks[@]}; do 105 ln -s rustup $link 106 done 107 popd 108 109 wrapProgram $out/bin/rustup --prefix "LD_LIBRARY_PATH" : "${libPath}" 110 111 # tries to create .rustup 112 mkdir -p "$out/share/"{bash-completion/completions,fish/vendor_completions.d,zsh/site-functions} 113 114 ${lib.optionalString (stdenv.hostPlatform.emulatorAvailable buildPackages) ( 115 let 116 emulator = stdenv.hostPlatform.emulator buildPackages; 117 in 118 '' 119 # generate completion scripts for rustup 120 installShellCompletion --cmd rustup \ 121 --bash <(${emulator} $out/bin/rustup completions bash rustup) \ 122 --fish <(${emulator} $out/bin/rustup completions fish rustup) \ 123 --zsh <(${emulator} $out/bin/rustup completions zsh rustup) 124 125 # generate completion scripts for cargo 126 # Note: fish completion script is not supported. 127 installShellCompletion --cmd cargo \ 128 --bash <(${emulator} $out/bin/rustup completions bash cargo) \ 129 --zsh <(${emulator} $out/bin/rustup completions zsh cargo) 130 '' 131 )} 132 133 # add a wrapper script for ld.lld 134 mkdir -p $out/nix-support 135 substituteAll ${../../../../../pkgs/build-support/wrapper-common/utils.bash} $out/nix-support/utils.bash 136 substituteAll ${../../../../../pkgs/build-support/wrapper-common/darwin-sdk-setup.bash} $out/nix-support/darwin-sdk-setup.bash 137 substituteAll ${../../../../../pkgs/build-support/bintools-wrapper/add-flags.sh} $out/nix-support/add-flags.sh 138 substituteAll ${../../../../../pkgs/build-support/bintools-wrapper/add-hardening.sh} $out/nix-support/add-hardening.sh 139 export prog='$PROG' 140 export use_response_file_by_default=0 141 substituteAll ${../../../../../pkgs/build-support/bintools-wrapper/ld-wrapper.sh} $out/nix-support/ld-wrapper.sh 142 chmod +x $out/nix-support/ld-wrapper.sh 143 ''; 144 145 env = { 146 inherit (stdenv.cc.bintools) 147 expandResponseParams 148 shell 149 suffixSalt 150 wrapperName 151 coreutils_bin 152 ; 153 hardening_unsupported_flags = ""; 154 }; 155 156 meta = { 157 description = "Rust toolchain installer"; 158 homepage = "https://www.rustup.rs/"; 159 license = with lib.licenses; [ 160 asl20 # or 161 mit 162 ]; 163 maintainers = with lib.maintainers; [ 164 mic92 165 ]; 166 mainProgram = "rustup"; 167 }; 168})