Skip to content

Commit

Permalink
vendorCargoRegistries: warn when registry names are not found (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
ipetkov authored Oct 7, 2024
1 parent 37e4f9f commit fd86b78
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 19 additions & 5 deletions lib/vendorCargoRegistries.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ let
concatMapStrings
concatStrings
escapeShellArg
filterAttrs
flatten
foldl
groupBy
hasPrefix
mapAttrs'
mapAttrsToList
nameValuePair
removePrefix;
removePrefix
warnIf;

inherit (lib.lists) unique;

Expand Down Expand Up @@ -71,16 +71,30 @@ 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 = {
"crates-io" = [ "https://github.com/rust-lang/crates.io-index" ];
} // (
if args ? registries
then mapAttrs (_: val: [ val ]) args.registries
else configuredRegistries // missingPackageRegistries
else warnIf (builtins.length missingPackageRegistries > 0) missingPackageRegistriesMsg configuredRegistries
);

sources = mapAttrs'
Expand Down

0 comments on commit fd86b78

Please sign in to comment.