nix-community / crate2nix

rebuild only changed crates in CI with crate2nix and nix
https://nix-community.github.io/crate2nix/
Apache License 2.0
335 stars 82 forks source link

Panic when running `crate2nix generate` #308

Closed C0D3-M4513R closed 8 months ago

C0D3-M4513R commented 8 months ago

Reproduction:

  1. git clone https://github.com/C0D3-M4513R/DexProtectOscRS.git
  2. cd DexProtectOscRS
  3. RUST_BACKTRACE=1 crate2nix generate
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', src/render.rs:237:33
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: crate2nix::render::cfg_to_nix_expr::render
   4: <F as tera::builtins::filters::Filter>::filter
   5: tera::renderer::processor::Processor::eval_filter
   6: tera::renderer::processor::Processor::eval_expression
   7: tera::renderer::processor::Processor::render_node
   8: tera::renderer::processor::Processor::render_node
   9: tera::renderer::processor::Processor::render_node
  10: tera::renderer::processor::Processor::render_node
  11: tera::renderer::processor::Processor::render_node
  12: tera::renderer::processor::Processor::render
  13: tera::renderer::Renderer::render
  14: tera::tera::Tera::render
  15: crate2nix::render::Template<C>::write_to_file
  16: crate2nix::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
savannidgerinel commented 8 months ago

I am also seeing this. In my case, I'm generating Cargo.nix from a workspace Cargo.toml and Cargo.lock file. The problem still occurs even when I filter down to just a single project in my workspace. Here's my repo, with a flake and a Cargo.toml: savanni/monorepo - monorepo - gitea: Gitea Service

I don't have a previous Cargo.nix, as I've been using cargo and shell scripts recently.

kolloch commented 8 months ago

Do you have the most recent crate2nix?

I cannot reproduce with the version from master

~/thirdparty/DexProtectOscRS main                                                                        23:18:09
❯ nix run github:nix-community/crate2nix -- generate
Generated ./Cargo.nix successfully.

(but I run into other problems that I will not debug right now on Mac Os at least)

/nix/store/6hl2zviscn0y7846zd0hv6wb9aqlrmaj-rust_objc-sys-0.2.0-beta.2-lib/env: line 1: export: `-fobjc-arc-exceptions': not a valid identifier
/nix/store/6hl2zviscn0y7846zd0hv6wb9aqlrmaj-rust_objc-sys-0.2.0-beta.2-lib/env: line 1: export: `-fobjc-exceptions': not a valid identifier
/nix/store/6hl2zviscn0y7846zd0hv6wb9aqlrmaj-rust_objc-sys-0.2.0-beta.2-lib/env: line 1: export: `-fobjc-runtime': not a valid identifier
/nix/store/ncnpn13v4h7qa8i9l5bbrd52wybj1irl-stdenv-darwin/setup: line 1681: pop_var_context: head of shell_variables not a function context
kolloch commented 8 months ago

@savannidgerinel also seems to work (i.e. not panic during render) for your repo on my system...

I'll close for now... Feel very free to reopen if you can reproduce with the version from master.

C0D3-M4513R commented 8 months ago

Huh can confirm. It works perfectly now... wtf?

savannidgerinel commented 8 months ago

@savannidgerinel also seems to work (i.e. not panic during render) for your repo on my system...

I'll close for now... Feel very free to reopen if you can reproduce with the version from master.

Oh.

So, I was using the edition of crate2nix from pkgs-23.05 and mis-reading other parts of my flake.nix where I thought I was pulling crate2nix directly from here.

kolloch commented 8 months ago

No worries :)