diff --git a/custom-pkgs/cargo-bisect-rustc/0001-patchelf.patch b/custom-pkgs/cargo-bisect-rustc/0001-patchelf.patch new file mode 100644 index 0000000..d0cbd3c --- /dev/null +++ b/custom-pkgs/cargo-bisect-rustc/0001-patchelf.patch @@ -0,0 +1,71 @@ +diff --git a/src/toolchains.rs b/src/toolchains.rs +index 16e68a0..5ce1c50 100644 +--- a/src/toolchains.rs ++++ b/src/toolchains.rs +@@ -34,6 +34,8 @@ pub(crate) enum InstallError { + TempDir(#[source] io::Error), + #[error("Could not move tempdir into destination: {0}")] + Move(#[source] io::Error), ++ #[error("Could not patchelf")] ++ Patchelf(#[source] io::Error), + #[error("Could not run subcommand {cmd}: {err}")] + Subcommand { + cmd: String, +@@ -208,7 +210,9 @@ impl Toolchain { + })?; + } + +- fs::rename(tmpdir.into_path(), dest).map_err(InstallError::Move) ++ fs::rename(tmpdir.into_path(), &dest).map_err(InstallError::Move)?; ++ nix_patchelf(dest).map_err(InstallError::Patchelf)?; ++ Ok(()) + } + + pub(crate) fn remove(&self, dl_params: &DownloadParams) -> io::Result<()> { +@@ -542,3 +546,46 @@ fn download_tarball( + res => res, + } + } ++ ++fn nix_patchelf(mut toolchain_path: PathBuf) -> Result<(), io::Error> { ++ toolchain_path.push("bin"); ++ ++ for entry in toolchain_path.read_dir()? { ++ let entry = entry?; ++ if !entry.file_type()?.is_file() { ++ continue; ++ } ++ ++ eprintln!( ++ "info: you seem to be running NixOS. Attempting to patch {}", ++ entry.path().to_str().unwrap() ++ ); ++ let _ = ::std::process::Command::new("@patchelf@/bin/patchelf") ++ .arg("--set-interpreter") ++ .arg("@dynamicLinker@") ++ .arg(entry.path()) ++ .output(); ++ } ++ ++ toolchain_path.pop(); ++ toolchain_path.push("lib"); ++ ++ for entry in toolchain_path.read_dir()? { ++ let entry = entry?; ++ if !entry.file_type()?.is_file() { ++ continue; ++ } ++ ++ eprintln!( ++ "info: you seem to be running NixOS. Attempting to patch {}", ++ entry.path().to_str().unwrap() ++ ); ++ let _ = ::std::process::Command::new("@patchelf@/bin/patchelf") ++ .arg("--set-rpath") ++ .arg("@libPath@") ++ .arg(entry.path()) ++ .output(); ++ } ++ ++ Ok(()) ++} diff --git a/custom-pkgs/cargo-bisect-rustc/default.nix b/custom-pkgs/cargo-bisect-rustc/default.nix new file mode 100644 index 0000000..1372515 --- /dev/null +++ b/custom-pkgs/cargo-bisect-rustc/default.nix @@ -0,0 +1,45 @@ +pkgs: pkgs.rustPlatform.buildRustPackage rec { + pname = "cargo-bisect-rustc"; + version = "0.6.6"; + + src = pkgs.fetchFromGitHub { + owner = "rust-lang"; + repo = "cargo-bisect-rustc"; + rev = "v${version}"; + hash = "sha256-i/MZslGbv72MZmd31SQFc2QdDRigs8edyN2/T5V5r4k="; + }; + + cargoHash = "sha256-dnR0V2MvW4Z3jtsjXSboCRFNb22fDGu01fC40N2Deho="; + + patches = + let + patchelfPatch = pkgs.runCommand "0001-patchelf.patch" + { + CC = pkgs.stdenv.cc; + patchelf = pkgs.patchelf; + libPath = "$ORIGIN/../lib:${pkgs.lib.makeLibraryPath [ pkgs.zlib ]}"; + } + '' + export dynamicLinker=$(cat $CC/nix-support/dynamic-linker) + substitute ${./0001-patchelf.patch} $out \ + --subst-var patchelf \ + --subst-var dynamicLinker \ + --subst-var libPath + ''; + in + pkgs.lib.optionals pkgs.stdenv.isLinux [ patchelfPatch ]; + + nativeBuildInputs = with pkgs; [ pkg-config ]; + buildInputs = with pkgs; [ openssl xz ]; + + PKG_CONFIG_PATH = "${pkgs.openssl}/lib"; + + # Tests access the network. + doCheck = false; + + meta = with pkgs.lib; { + description = "Bisects rustc, either nightlies or CI artifacts"; + homepage = "https://github.com/rust-lang/cargo-bisect-rustc"; + license = licenses.mit; + }; +} diff --git a/custom-pkgs/default.nix b/custom-pkgs/default.nix new file mode 100644 index 0000000..cc61340 --- /dev/null +++ b/custom-pkgs/default.nix @@ -0,0 +1,3 @@ +pkgs: { + cargo-bisect-rustc = import ./cargo-bisect-rustc/default.nix pkgs; +} diff --git a/home-manager/home.nix b/home-manager/home.nix index bab3786..07acb93 100644 --- a/home-manager/home.nix +++ b/home-manager/home.nix @@ -6,7 +6,10 @@ , config , pkgs , ... -}: { +}: +let customPkgs = import ../custom-pkgs/default.nix pkgs; +in +{ # You can import other home-manager modules here imports = [ # If you want to use home-manager modules from other flakes (such as nix-colors): @@ -65,6 +68,7 @@ rustup-toolchain-install-master inferno gh + customPkgs.cargo-bisect-rustc ]; # Enable home-manager and git