Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility warning with nixpkgs >= NixOS 24.11 #332

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions rust-overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ let
channel_by_version
);

# In NixOS 24.11, the `pkgs.rust.toRustTarget` has become deprecated in favor of the
# `.rust.rustcTarget` attribute of the platform. This function provides backwards compatibility in
# case the caller is using a nixpkgs older than NixOS 24.11.
toRustTargetCompat = platform:
if platform ? rust && platform.rust ? rustcTarget
then platform.rust.rustcTarget
else super.rust.toRustTarget platform;

# See https://github.com/rust-lang-nursery/rustup.rs/blob/master/src/dist/src/dist.rs
defaultDistRoot = "https://static.rust-lang.org";
manifest_v1_url = {
Expand Down Expand Up @@ -59,7 +67,7 @@ let
getComponentsWithFixedPlatform = pkgs: pkgname: stdenv:
let
pkg = pkgs.${pkgname};
srcInfo = pkg.target.${super.rust.toRustTarget stdenv.targetPlatform} or pkg.target."*";
srcInfo = pkg.target.${toRustTargetCompat stdenv.targetPlatform} or pkg.target."*";
components = srcInfo.components or [];
componentNamesList =
builtins.map (pkg: pkg.pkg) (builtins.filter (pkg: (pkg.target != "*")) components);
Expand All @@ -70,7 +78,7 @@ let
let
inherit (super.lib) unique;
pkg = pkgs.${pkgname};
srcInfo = pkg.target.${super.rust.toRustTarget stdenv.targetPlatform} or pkg.target."*";
srcInfo = pkg.target.${toRustTargetCompat stdenv.targetPlatform} or pkg.target."*";
extensions = srcInfo.extensions or [];
extensionNamesList = unique (builtins.map (pkg: pkg.pkg) extensions);
in
Expand Down Expand Up @@ -125,7 +133,7 @@ let
inherit (super.lib) flatten remove subtractLists unique;
targetExtensionsToInstall = checkMissingExtensions pkgs pkgname stdenv targetExtensions;
extensionsToInstall = checkMissingExtensions pkgs pkgname stdenv extensions;
hostTargets = [ "*" (super.rust.toRustTarget stdenv.hostPlatform) (super.rust.toRustTarget stdenv.targetPlatform) ];
hostTargets = [ "*" (toRustTargetCompat stdenv.hostPlatform) (toRustTargetCompat stdenv.targetPlatform) ];
pkgTuples = flatten (getTargetPkgTuples pkgs pkgname hostTargets targets stdenv);
extensionTuples = flatten (map (name: getTargetPkgTuples pkgs name hostTargets targets stdenv) extensionsToInstall);
targetExtensionTuples = flatten (map (name: getTargetPkgTuples pkgs name targets targets stdenv) targetExtensionsToInstall);
Expand Down