1{ stdenv
2, lib
3, runCommand
4, patchelf
5, fetchFromGitHub
6, rustPlatform
7, makeWrapper
8, pkg-config
9, curl
10, zlib
11, Security
12, CoreServices
13, libiconv
14, xz
15}:
16
17let
18 libPath = lib.makeLibraryPath [
19 zlib # libz.so.1
20 ];
21in
22
23rustPlatform.buildRustPackage rec {
24 pname = "rustup";
25 version = "1.24.3";
26
27 src = fetchFromGitHub {
28 owner = "rust-lang";
29 repo = "rustup";
30 rev = version;
31 sha256 = "sha256-JpOOFwlTgwwBCrXOGYskFTgS6RZ7mHQJGT0jnHavxvI=";
32 };
33
34 cargoSha256 = "sha256-hAfGpKaWD94IxFFpnW9XwQp4P9clUX6mmekwodCK0Ag=";
35
36 nativeBuildInputs = [ makeWrapper pkg-config ];
37
38 buildInputs = [
39 curl
40 zlib
41 ] ++ lib.optionals stdenv.isDarwin [ CoreServices Security libiconv xz ];
42
43 buildFeatures = [ "no-self-update" ];
44
45 checkFeatures = [ ];
46
47 patches = lib.optionals stdenv.isLinux [
48 (runCommand "0001-dynamically-patchelf-binaries.patch" { CC = stdenv.cc; patchelf = patchelf; libPath = "$ORIGIN/../lib:${libPath}"; } ''
49 export dynamicLinker=$(cat $CC/nix-support/dynamic-linker)
50 substitute ${./0001-dynamically-patchelf-binaries.patch} $out \
51 --subst-var patchelf \
52 --subst-var dynamicLinker \
53 --subst-var libPath
54 '')
55 ];
56
57 doCheck = !stdenv.isAarch64 && !stdenv.isDarwin;
58
59 postInstall = ''
60 pushd $out/bin
61 mv rustup-init rustup
62 binlinks=(
63 cargo rustc rustdoc rust-gdb rust-lldb rls rustfmt cargo-fmt
64 cargo-clippy clippy-driver cargo-miri
65 )
66 for link in ''${binlinks[@]}; do
67 ln -s rustup $link
68 done
69 popd
70
71 wrapProgram $out/bin/rustup --prefix "LD_LIBRARY_PATH" : "${libPath}"
72
73 # tries to create .rustup
74 export HOME=$(mktemp -d)
75 mkdir -p "$out/share/"{bash-completion/completions,fish/vendor_completions.d,zsh/site-functions}
76
77 # generate completion scripts for rustup
78 $out/bin/rustup completions bash rustup > "$out/share/bash-completion/completions/rustup"
79 $out/bin/rustup completions fish rustup > "$out/share/fish/vendor_completions.d/rustup.fish"
80 $out/bin/rustup completions zsh rustup > "$out/share/zsh/site-functions/_rustup"
81
82 # generate completion scripts for cargo
83 # Note: fish completion script is not supported.
84 $out/bin/rustup completions bash cargo > "$out/share/bash-completion/completions/cargo"
85 $out/bin/rustup completions zsh cargo > "$out/share/zsh/site-functions/_cargo"
86 '';
87
88 meta = with lib; {
89 description = "The Rust toolchain installer";
90 homepage = "https://www.rustup.rs/";
91 license = with licenses; [ asl20 /* or */ mit ];
92 maintainers = [ maintainers.mic92 ];
93 };
94}