nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ stdenv
2, lib
3, runCommand
4, patchelf
5, fetchFromGitHub
6, rustPlatform
7, makeBinaryWrapper
8, pkg-config
9, openssl
10, curl
11, zlib
12, Security
13, CoreServices
14, libiconv
15, xz
16}:
17
18let
19 libPath = lib.makeLibraryPath [
20 zlib # libz.so.1
21 ];
22in
23
24rustPlatform.buildRustPackage rec {
25 pname = "rustup";
26 version = "1.26.0";
27
28 src = fetchFromGitHub {
29 owner = "rust-lang";
30 repo = "rustup";
31 rev = version;
32 sha256 = "sha256-rdhG9MdjWyvoaMGdjgFyCfQaoV48QtAZE7buA5TkDKg=";
33 };
34
35 cargoLock = {
36 lockFile = ./Cargo.lock;
37 };
38
39 nativeBuildInputs = [ makeBinaryWrapper pkg-config ];
40
41 buildInputs = [
42 (curl.override { inherit openssl; })
43 zlib
44 ] ++ lib.optionals stdenv.isDarwin [ CoreServices Security libiconv xz ];
45
46 buildFeatures = [ "no-self-update" ];
47
48 checkFeatures = [ ];
49
50 patches = lib.optionals stdenv.isLinux [
51 (runCommand "0001-dynamically-patchelf-binaries.patch"
52 {
53 CC = stdenv.cc;
54 patchelf = patchelf;
55 libPath = "${libPath}";
56 } ''
57 export dynamicLinker=$(cat $CC/nix-support/dynamic-linker)
58 substitute ${./0001-dynamically-patchelf-binaries.patch} $out \
59 --subst-var patchelf \
60 --subst-var dynamicLinker \
61 --subst-var libPath
62 '')
63 ];
64
65 doCheck = !stdenv.isAarch64 && !stdenv.isDarwin;
66
67 # skip failing tests
68 checkFlags = [
69 # auto-self-update mode is set to 'disable' for nix rustup
70 "--skip=suite::cli_exact::check_updates_none"
71 "--skip=suite::cli_exact::check_updates_some"
72 "--skip=suite::cli_exact::check_updates_with_update"
73 # rustup-init is not used in nix rustup
74 "--skip=suite::cli_ui::rustup_init_ui_doc_text_tests"
75 ];
76
77 postInstall = ''
78 pushd $out/bin
79 mv rustup-init rustup
80 binlinks=(
81 cargo rustc rustdoc rust-gdb rust-lldb rls rustfmt cargo-fmt
82 cargo-clippy clippy-driver cargo-miri rust-gdbgui rust-analyzer
83 )
84 for link in ''${binlinks[@]}; do
85 ln -s rustup $link
86 done
87 popd
88
89 wrapProgram $out/bin/rustup --prefix "LD_LIBRARY_PATH" : "${libPath}"
90
91 # tries to create .rustup
92 export HOME=$(mktemp -d)
93 mkdir -p "$out/share/"{bash-completion/completions,fish/vendor_completions.d,zsh/site-functions}
94
95 # generate completion scripts for rustup
96 $out/bin/rustup completions bash rustup > "$out/share/bash-completion/completions/rustup"
97 $out/bin/rustup completions fish rustup > "$out/share/fish/vendor_completions.d/rustup.fish"
98 $out/bin/rustup completions zsh rustup > "$out/share/zsh/site-functions/_rustup"
99
100 # generate completion scripts for cargo
101 # Note: fish completion script is not supported.
102 $out/bin/rustup completions bash cargo > "$out/share/bash-completion/completions/cargo"
103 $out/bin/rustup completions zsh cargo > "$out/share/zsh/site-functions/_cargo"
104
105 # add a wrapper script for ld.lld
106 mkdir -p $out/nix-support
107 substituteAll ${../../../../../pkgs/build-support/wrapper-common/utils.bash} $out/nix-support/utils.bash
108 substituteAll ${../../../../../pkgs/build-support/bintools-wrapper/add-flags.sh} $out/nix-support/add-flags.sh
109 substituteAll ${../../../../../pkgs/build-support/bintools-wrapper/add-hardening.sh} $out/nix-support/add-hardening.sh
110 export prog='$PROG'
111 export use_response_file_by_default=0
112 substituteAll ${../../../../../pkgs/build-support/bintools-wrapper/ld-wrapper.sh} $out/nix-support/ld-wrapper.sh
113 chmod +x $out/nix-support/ld-wrapper.sh
114 '';
115
116 env = lib.optionalAttrs (pname == "rustup") {
117 inherit (stdenv.cc.bintools) expandResponseParams shell suffixSalt wrapperName coreutils_bin;
118 hardening_unsupported_flags = "";
119 };
120
121 meta = with lib; {
122 description = "Rust toolchain installer";
123 homepage = "https://www.rustup.rs/";
124 license = with licenses; [ asl20 /* or */ mit ];
125 maintainers = [ maintainers.mic92 ];
126 };
127}