ITADN

bug: mkDummySrc tries to parse Cargo.toml files outside of src

#985OpenEpicEric 创建于 2026-03-07
bug
E
EpicEriccommented
### Describe the bug I have a repo that includes a `Cargo.toml` somewhere in its node_modules, which is used as a jinja-like template. It looks like this: ```toml # Generated by uniffi-bindgen-react-native {%- let root = project_root() %} {%- let crate_dir = config.project.crate_.crate_dir_relative(root) %} {%- let crate_dir = relative_to(root, crate_dir) %} [package] name = "{{ config.project.wasm.wasm_crate_name() }}" version = "{{ config.project.project_version() }}" edition = "2018" # ... etc ... ``` It's clearly not valid TOML, but it's not included in my source fileset (it's not even tracked by Git). Nevertheless, crane will still error because it failed to parse it. ### Reproduction A minimal repro is available on <https://github.com/EpicEric/crane-repro-985> The invalid Cargo.toml is in `trash/`, which is not included in the `src` fileset, but trying to build still generates an error: ``` $ nix build . --show-trace error: … while calling the 'derivationStrict' builtin at <nix/derivation-internal.nix>:37:12: 36| 37| strict = derivationStrict drvAttrs; | ^ 38| … while evaluating derivation 'blah-0.1.0' whose name attribute is located at /nix/store/az8lhj92ggbhkvkssl3ahf4c9d387h2g-source/pkgs/stdenv/generic/make-derivation.nix:536:13 … while evaluating attribute 'cargoArtifacts' of derivation 'blah-0.1.0' at /nix/store/bwhcmkxjsqyy8g980shwjmwv7gnfh3p5-source/lib/mkCargoDerivation.nix:90:13: 89| // { 90| inherit cargoArtifacts; | ^ 91| … while calling the 'getAttr' builtin at <nix/derivation-internal.nix>:50:17: 49| value = commonAttrs // { 50| outPath = builtins.getAttr outputName strict; | ^ 51| drvPath = strict.drvPath; … while calling the 'derivationStrict' builtin at <nix/derivation-internal.nix>:37:12: 36| 37| strict = derivationStrict drvAttrs; | ^ 38| … while evaluating derivation 'blah-deps-0.1.0' whose name attribute is located at /nix/store/az8lhj92ggbhkvkssl3ahf4c9d387h2g-source/pkgs/stdenv/generic/make-derivation.nix:536:13 … while evaluating attribute 'src' of derivation 'blah-deps-0.1.0' at /nix/store/bwhcmkxjsqyy8g980shwjmwv7gnfh3p5-source/lib/buildDepsOnly.nix:57:5: 56| 57| src = dummySrc; | ^ 58| pnameSuffix = "-deps"; … while calling the 'getAttr' builtin at <nix/derivation-internal.nix>:50:17: 49| value = commonAttrs // { 50| outPath = builtins.getAttr outputName strict; | ^ 51| drvPath = strict.drvPath; … while calling the 'derivationStrict' builtin at <nix/derivation-internal.nix>:37:12: 36| 37| strict = derivationStrict drvAttrs; | ^ 38| … while evaluating derivation 'source' whose name attribute is located at /nix/store/az8lhj92ggbhkvkssl3ahf4c9d387h2g-source/pkgs/stdenv/generic/make-derivation.nix:536:13 … while evaluating attribute 'buildCommand' of derivation 'source' at /nix/store/az8lhj92ggbhkvkssl3ahf4c9d387h2g-source/pkgs/build-support/trivial-builders/default.nix:80:17: 79| enableParallelBuilding = true; 80| inherit buildCommand name; | ^ 81| passAsFile = [ "buildCommand" ] ++ (derivationArgs.passAsFile or [ ]); … while calling the 'concatStringsSep' builtin at /nix/store/bwhcmkxjsqyy8g980shwjmwv7gnfh3p5-source/lib/mkDummySrc.nix:131:27: 130| 131| copyAndStubCargoTomls = concatStrings ( | ^ 132| map ( … while calling anonymous lambda at /nix/store/bwhcmkxjsqyy8g980shwjmwv7gnfh3p5-source/lib/mkDummySrc.nix:133:7: 132| map ( 133| p: | ^ 134| let … while calling the 'getAttr' builtin at <nix/derivation-internal.nix>:50:17: 49| value = commonAttrs // { 50| outPath = builtins.getAttr outputName strict; | ^ 51| drvPath = strict.drvPath; … while calling the 'derivationStrict' builtin at <nix/derivation-internal.nix>:37:12: 36| 37| strict = derivationStrict drvAttrs; | ^ 38| … while evaluating derivation 'Cargo.toml' whose name attribute is located at /nix/store/az8lhj92ggbhkvkssl3ahf4c9d387h2g-source/pkgs/stdenv/generic/make-derivation.nix:536:13 … while evaluating attribute 'contents' of derivation 'Cargo.toml' at /nix/store/bwhcmkxjsqyy8g980shwjmwv7gnfh3p5-source/lib/writeTOML.nix:14:5: 13| { 14| contents = builtins.toJSON contents; | ^ 15| passAsFile = [ "contents" ]; … while calling the 'toJSON' builtin at /nix/store/bwhcmkxjsqyy8g980shwjmwv7gnfh3p5-source/lib/writeTOML.nix:14:16: 13| { 14| contents = builtins.toJSON contents; | ^ 15| passAsFile = [ "contents" ]; … while evaluating a branch condition at /nix/store/bwhcmkxjsqyy8g980shwjmwv7gnfh3p5-source/lib/mkDummySrc.nix:218:11: 217| # Only update if we have a `package` definition, workspaces Cargo.tomls don't need updating 218| if cleanedCargoToml ? package then | ^ 219| recursiveUpdate cleanedCargoToml { … while calling a functor (an attribute set with a '__functor' attribute) at /nix/store/bwhcmkxjsqyy8g980shwjmwv7gnfh3p5-source/lib/mkDummySrc.nix:145:28: 144| 145| cleanedCargoToml = cleanCargoToml ( | ^ 146| { … from call site at /nix/store/az8lhj92ggbhkvkssl3ahf4c9d387h2g-source/lib/trivial.nix:1081:5: 1080| # TODO: Should we add call-time "type" checking like built in? 1081| __functor = self: f; | ^ 1082| __functionArgs = args; … while calling anonymous lambda at /nix/store/bwhcmkxjsqyy8g980shwjmwv7gnfh3p5-source/lib/cleanCargoToml.nix:29:1: 28| in 29| { | ^ 30| cargoToml ? throw "either cargoToml or cargoTomlContents must be specified", … from call site at /nix/store/bwhcmkxjsqyy8g980shwjmwv7gnfh3p5-source/lib/cleanCargoToml.nix:35:1: 34| }: 35| filterData cleanCargoTomlFilter (builtins.fromTOML cargoTomlContents) | ^ 36| … while calling 'filterData' at /nix/store/bwhcmkxjsqyy8g980shwjmwv7gnfh3p5-source/lib/cleanCargoToml.nix:27:22: 26| val; 27| filterData = pred: val: filterData' pred [ ] val; | ^ 28| in … from call site at /nix/store/bwhcmkxjsqyy8g980shwjmwv7gnfh3p5-source/lib/cleanCargoToml.nix:27:27: 26| val; 27| filterData = pred: val: filterData' pred [ ] val; | ^ 28| in … while calling 'filterData'' at /nix/store/bwhcmkxjsqyy8g980shwjmwv7gnfh3p5-source/lib/cleanCargoToml.nix:10:17: 9| filterData' = 10| pred: path: val: | ^ 11| if builtins.isAttrs val then … while evaluating a branch condition at /nix/store/bwhcmkxjsqyy8g980shwjmwv7gnfh3p5-source/lib/cleanCargoToml.nix:11:5: 10| pred: path: val: 11| if builtins.isAttrs val then | ^ 12| builtins.listToAttrs ( … while calling the 'isAttrs' builtin at /nix/store/bwhcmkxjsqyy8g980shwjmwv7gnfh3p5-source/lib/cleanCargoToml.nix:11:8: 10| pred: path: val: 11| if builtins.isAttrs val then | ^ 12| builtins.listToAttrs ( … while calling the 'fromTOML' builtin at /nix/store/bwhcmkxjsqyy8g980shwjmwv7gnfh3p5-source/lib/cleanCargoToml.nix:35:34: 34| }: 35| filterData cleanCargoTomlFilter (builtins.fromTOML cargoTomlContents) | ^ 36| error: while parsing TOML: [error] toml::parse_simple_key: invalid key: key must be "quoted", 'quoted-literal', or bare key. --> fromTOML | 1 | { | ^-- expected alpha [a-zA-Z], digit [0-9], -, or _ Hint: non-ASCII scripts are allowed in toml v1.1.0, but not in v1.0.0. [error] toml::parse_key_value_pair: invalid key value separator `=` --> fromTOML | 2 | "foo": "bar" | ^-- expected = [error] toml::parse_simple_key: invalid key: key must be "quoted", 'quoted-literal', or bare key. --> fromTOML | 3 | } | ^-- expected alpha [a-zA-Z], digit [0-9], -, or _ Hint: non-ASCII scripts are allowed in toml v1.1.0, but not in v1.0.0. ```
0 条评论