From fd86b78f5f35f712c72147427b1eb81a9bd55d0b Mon Sep 17 00:00:00 2001 From: Ivan Petkov Date: Mon, 7 Oct 2024 16:39:36 -0700 Subject: [PATCH] vendorCargoRegistries: warn when registry names are not found (#716) --- CHANGELOG.md | 6 ++++++ lib/vendorCargoRegistries.nix | 24 +++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c27000a5..5314949c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +### Fixed +* Vendoring dependencies avoids creating malformed TOML configurations in + situations where registry name/url definitions cannot be found. When this + happens a warning will be printed out during evaluation to highlight the + issue. + ## [0.19.0] - 2024-09-25 ### Added diff --git a/lib/vendorCargoRegistries.nix b/lib/vendorCargoRegistries.nix index c0836362..63b2600d 100644 --- a/lib/vendorCargoRegistries.nix +++ b/lib/vendorCargoRegistries.nix @@ -23,7 +23,6 @@ let concatMapStrings concatStrings escapeShellArg - filterAttrs flatten foldl groupBy @@ -31,7 +30,8 @@ let mapAttrs' mapAttrsToList nameValuePair - removePrefix; + removePrefix + warnIf; inherit (lib.lists) unique; @@ -71,8 +71,22 @@ let # Registries referenced in Cargo.lock that are missing from cargo config existingRegistries = foldl (acc: r: acc // { ${removeProtocol r.value.index} = true; }) { "https://github.com/rust-lang/crates.io-index" = true; } allCargoRegistryPairsWithIndex; - allPackageRegistries = foldl (acc: p: if p ? source then acc // { ${removeProtocol p.source} = [ p.source ]; } else acc) { } lockPackages; - missingPackageRegistries = filterAttrs (name: _: !(existingRegistries ? ${name})) allPackageRegistries; + missingPackageRegistries = filter (r: !(existingRegistries ? ${r})) + (map (p: removeProtocol p.source) (filter (p: p ? source && (! hasPrefix "git+" p.source)) lockPackages)); + + missingPackageRegistriesMsg = '' + unable to find registry name/url configurations for the registries below: + ${concatStringsSep "\n" missingPackageRegistries} + + any attempt to build with this set of vendored dependencies is likely to fail. + to resolve this consider one of the following: + + - add `.cargo/config.toml` at the root of the `src` attribute which configures a + registry. Make sure this file is staged via `git add` if using flakes. + https://doc.rust-lang.org/cargo/reference/registries.html#using-an-alternate-registry + - otherwise set `cargoConfigs` when calling `vendorCargoDeps` and friends + which contains the appropriate registry definitions + ''; # Append the default crates.io registry, but allow it to be overridden registries = { @@ -80,7 +94,7 @@ let } // ( if args ? registries then mapAttrs (_: val: [ val ]) args.registries - else configuredRegistries // missingPackageRegistries + else warnIf (builtins.length missingPackageRegistries > 0) missingPackageRegistriesMsg configuredRegistries ); sources = mapAttrs'