diff options
Diffstat (limited to 'pkgs/rust')
| -rw-r--r-- | pkgs/rust/lib/crate2nix-package.nix | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/pkgs/rust/lib/crate2nix-package.nix b/pkgs/rust/lib/crate2nix-package.nix index dae8fd04..0c867ee2 100644 --- a/pkgs/rust/lib/crate2nix-package.nix +++ b/pkgs/rust/lib/crate2nix-package.nix @@ -138,7 +138,32 @@ let if cargoLock == null || missing == [] then result else throw "crate2nix-package: ${toString resolvedJson'} is stale against ${toString cargoLock}; not in the lock: ${lib.concatStringsSep ", " (lib.take 5 missing)}${lib.optionalString (builtins.length missing > 5) ", ..."}"; - cargoNix = if useJson then checkFeatures (checkLock fromJson) else fromLock; + # Fails evaluation if the root crate's Cargo.toml has a dependency the + # plan's root crate doesn't, i.e. one added since Cargo.json was + # generated, which checkLock doesn't see. Optional ones and + # dev-dependencies don't count: the plan may leave them out. + checkDependencies = result: + let + manifest = builtins.fromTOML (builtins.readFile cargoToml); + tables = [ manifest ] ++ lib.attrValues (manifest.target or { }); + declared = lib.concatMap + (table: lib.concatMap + (kind: lib.mapAttrsToList + (name: spec: + if !builtins.isAttrs spec then name + else if spec.optional or false then null + else spec.package or name) + (table.${kind} or { })) + [ "dependencies" "build-dependencies" ]) + tables; + root = plan.crates.${plan.root}; + planned = map (dep: dep.name) (root.dependencies or [ ] ++ root.buildDependencies or [ ]); + missing = lib.subtractLists planned (lib.unique (builtins.filter (name: name != null) declared)); + in + if cargoToml == null || plan.root or null == null || missing == [ ] then result + else throw "crate2nix-package: ${toString resolvedJson'} is stale against ${toString cargoToml}; not in the plan: ${lib.concatStringsSep ", " missing}"; + + cargoNix = if useJson then checkDependencies (checkFeatures (checkLock fromJson)) else fromLock; in cargoNix // { build = let |
