summaryrefslogtreecommitdiffstats
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
commitca40883e55ed3b54f6a1f8fa3d697bdf3547c8de (patch)
tree16b4bcd2465b5e50bf1f19af8fff7f8f7bf9f7e0
parente2a2afaa2a239ba7acddf8e42940caa49bc7f24b (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.
-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
[cgit] Unable to lock slot /tmp/cgit/0d100000.lock: Permission denied (13)