summaryrefslogtreecommitdiffstats
path: root/pkgs/rust
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-02 17:18:42 +0000
committertv <tv@krebsco.de>2026-12-02 18:02:30 +0000
commit7865eec153b2e87f0d50c195ce9fac22b1f922f6 (patch)
tree3cd552804b15e8eaf9b3c20f5dcf69cd6ea68d2e /pkgs/rust
parent905696c76f1a8828f9c422955a494516dd8bddfa (diff)
crate2nix-package: catch dependencies added since the plan
checkLock only sees crates the plan has and the lock doesn't, so a plan older than a new dependency, like enstate's libc, passed and the build failed. Now the root crate's non-optional dependencies in Cargo.toml must be in the plan.
Diffstat (limited to 'pkgs/rust')
-rw-r--r--pkgs/rust/lib/crate2nix-package.nix27
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