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