master ← samestep:nix-env-meta-main-program
opened 05:27PM - 05 Jun 26 UTC
This PR resolves #317, enabling downstream tools like comma to see packages that… Hydra doesn't build.
I would strongly recommend reviewing the two commits of this PR separately.
The first commit rewrites the parser for [`nix-env --query --xml`](https://nix.dev/manual/nix/2.34/command-ref/nix-env/query). I did this because I found the existing parser extremely unwieldy and difficult to modify. The rewrite uses Serde via [quick-xml](https://crates.io/crates/quick-xml), is significantly less code, and is roughly 4x faster than before. While the new double usage of `.collect` in `listings::fetch` may look a bit suspicious, the memory usage is not significantly different from before.
The second commit implements the actual feature: passing the `--meta` flag to that `nix-env --query` command so that we can extract `meta.mainProgram` when it's available. That is then threaded through along with the store path, and in cases where Hydra doesn't have it, a synthesized `/bin/$mainProgram` file listing is created. This whole thing can be turned off via `nix-index --no-main-program`, which simply doesn't add the `--meta` flag and so no `meta.mainProgram` entries are created in the first place.
A few notes/questions I have for the reviewer(s):
1. Should this PR modify `CHANGELOG.md`?
2. Is it fine that we say the size of executable file is zero bytes, and give an empty string for the nar? It seems like the former is simply displayed by nix-locate and the latter is only used for debugging (and thus would never be used in this case anyway), but I wanted to double-check.
3. This PR doesn't use quick-xml in such a way that the error messages include line or column numbers. Is that fine?
4. While the rewritten parser from the first commit is about 4x faster than the previous parser, adding the `--meta` flag causes the XML output to be 10x bigger, and in the end, when we feed that bigger XML into the new parser, it's about 3x slower than feeding the smaller XL into the original parser. I'm guessing this is fine since parsing this XML isn't really a bottleneck?
5. I don't love that now `nixpkgs::query_packages` and `listings::fetch` each have _two_ boolean flags passed positionally. But I'm also not sure it's worth it to create a `struct` in this case.