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.27.1";
29
30 src = fetchFromGitHub {
31 owner = "rust-lang";
32 repo = "rustup";
33 tag = finalAttrs.version;
34 hash = "sha256-BehkJTEIbZHaM+ABaWN/grl9pX75lPqyBj1q1Kt273M=";
35 };
36
37 useFetchCargoVendor = true;
38 cargoHash = "sha256-CQHpsOGofDqsbLLTcznu5a0MSthJgy27HjBk8AYA72s=";
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
83 # skip failing tests
84 checkFlags = [
85 # auto-self-update mode is set to 'disable' for nix rustup
86 "--skip=suite::cli_exact::check_updates_none"
87 "--skip=suite::cli_exact::check_updates_some"
88 "--skip=suite::cli_exact::check_updates_with_update"
89 # rustup-init is not used in nix rustup
90 "--skip=suite::cli_ui::rustup_init_ui_doc_text_tests"
91 ];
92
93 postInstall = ''
94 pushd $out/bin
95 mv rustup-init rustup
96 binlinks=(
97 cargo rustc rustdoc rust-gdb rust-lldb rls rustfmt cargo-fmt
98 cargo-clippy clippy-driver cargo-miri rust-gdbgui rust-analyzer
99 )
100 for link in ''${binlinks[@]}; do
101 ln -s rustup $link
102 done
103 popd
104
105 wrapProgram $out/bin/rustup --prefix "LD_LIBRARY_PATH" : "${libPath}"
106
107 # tries to create .rustup
108 mkdir -p "$out/share/"{bash-completion/completions,fish/vendor_completions.d,zsh/site-functions}
109
110 ${lib.optionalString (stdenv.hostPlatform.emulatorAvailable buildPackages) (
111 let
112 emulator = stdenv.hostPlatform.emulator buildPackages;
113 in
114 ''
115 # generate completion scripts for rustup
116 installShellCompletion --cmd rustup \
117 --bash <(${emulator} $out/bin/rustup completions bash rustup) \
118 --fish <(${emulator} $out/bin/rustup completions fish rustup) \
119 --zsh <(${emulator} $out/bin/rustup completions zsh rustup)
120
121 # generate completion scripts for cargo
122 # Note: fish completion script is not supported.
123 installShellCompletion --cmd cargo \
124 --bash <(${emulator} $out/bin/rustup completions bash cargo) \
125 --zsh <(${emulator} $out/bin/rustup completions zsh cargo)
126 ''
127 )}
128
129 # add a wrapper script for ld.lld
130 mkdir -p $out/nix-support
131 substituteAll ${../../../../../pkgs/build-support/wrapper-common/utils.bash} $out/nix-support/utils.bash
132 substituteAll ${../../../../../pkgs/build-support/wrapper-common/darwin-sdk-setup.bash} $out/nix-support/darwin-sdk-setup.bash
133 substituteAll ${../../../../../pkgs/build-support/bintools-wrapper/add-flags.sh} $out/nix-support/add-flags.sh
134 substituteAll ${../../../../../pkgs/build-support/bintools-wrapper/add-hardening.sh} $out/nix-support/add-hardening.sh
135 export prog='$PROG'
136 export use_response_file_by_default=0
137 substituteAll ${../../../../../pkgs/build-support/bintools-wrapper/ld-wrapper.sh} $out/nix-support/ld-wrapper.sh
138 chmod +x $out/nix-support/ld-wrapper.sh
139 '';
140
141 env = {
142 inherit (stdenv.cc.bintools)
143 expandResponseParams
144 shell
145 suffixSalt
146 wrapperName
147 coreutils_bin
148 ;
149 hardening_unsupported_flags = "";
150 };
151
152 meta = {
153 description = "Rust toolchain installer";
154 homepage = "https://www.rustup.rs/";
155 license = with lib.licenses; [
156 asl20 # or
157 mit
158 ];
159 maintainers = with lib.maintainers; [
160 mic92
161 ];
162 mainProgram = "rustup";
163 };
164})