-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convenient support for out-of-tree sources #102
Comments
That does sound good. How do you think about just providing an identiier from crates.io (as an alternative path)? Perhaps I am thinking a bit too far here but having the ability to feed crate2nix a list of crates (from crates.io) would be nice for cli tools (and testing a bunch of crates for compatibility, caching them on a binary cache, …). |
Regarding inclusion into nixpkgs: How big would be the generated files? |
@Mic92 Pretty much proportional to the number of transitive dependencies - 135KB for Crate2nix for hundreds of dependencies. 2-3 times the size of Similar binaries could be grouped into virtual workspaces so that their dependencies resolve to the same versions where possible and to avoid duplication. |
Oh, the |
I wonder if recursive nix could be used to avoid having the generated files. |
You can easily avoid checking in the generated files with "import from derivation". With recursive nix, you have to know all your dependencies beforehand - so, no, that doesn't help. You could code most of the functionality of crate2nix in nix itself now that the Toml parser in nix is good enough. Then you would still need to copy the And speed is probably the main concern? Because of the template language, the dependency tree of |
The approach with checking in the |
Yeah speed and memory consumption are the main concern we have with evaluation of nixpkgs. |
I think we can cut down on file size by a factor of two or so -- afterwards it becomes difficult if it should stay readable. We at least have to preserve the info that allows feature resolution and the information necessary to retrieve the code. |
I pushed early but fairly complete support for out-of-tree sources! See https://github.com/kolloch/crate2nix/blob/master/out-of-tree-sources.md for a description. This does not (yet) try to trim down the size of the generated nix-file since that is somewhat orthogonal. Tell me what you think! @Mic92 @andir |
This looks really good. I just tried it. For use in nixpkgs we probably would import the |
I just tried to package a couple of command line tools we have in nixpkgs:
However it run into conflicts:
Here is the full list of sources: sources.nix.txt
Do you think there is a way to work around these conflicts? |
Hi @Mic92, Thank you so much for your experiments! ConflictsAaah, to bad about the conflicts in the native libraries. Since crate2nix would libs independently again, I think that this would actually not lead to compile time errors. But the cargo error blocks this. I see two ways forward:
I'll give it a go and report back. It would basically mean that the Resolving deps without CargoI am fairly confident that I could write the resolver in rust. It is actually quite easy to read the index and so on. Similar to a vendored index, this resolving could even happen in a derivation (well, not in nixpkgs because of the import-from-derivation not-wanted issue) I implemented the version matching in nix today/yesterday, because, ...ehem... an invisible force made me. ;) https://github.com/kolloch/nix-cargo-index It is not terribly fast, though, but fun to play with! The most complex piece is the semver parser. I wonder if someone already wrote one... In rust code, I could just use the existing crate to do that.. nivI basically included the "Nix" source type also as an escape hatch to do crazy stuff but mostly for niv. It definitely makes sense for github sources. Ergonomically, I could even make using niv sources easier by including an option to make "--import ./nix/sources.nix" the default for "source add nix". In that case you'd only have to write |
We require so far
This has the advantage though that we build the same version that upstream tests.
Should be straightforward to fix. Otherwise does nix-prefetch work for you?
Would this produce the same results as cargo's dependencies tree.
Do you think it could run into performance problems if we have more packages?
Yes that would be great! Right now we would have redundant information. |
store path support for nix-prefetch-git: NixOS/nixpkgs#85511 |
Thank you :) |
Cargo.lock vs other dependency resolution: I think you lean towards going with the Cargo.lock files from upstream for now. And I agree. Advantage: Same versions as upstream, probably working better. Disadvantage: More minor version differences. I agree. Overall, reliability is more important than squashing build time. I'll try to make this work. If we get into trouble with scaling to a lot of packages, the workaround is simple: Use multiple workspaces. That said, I could imagine that it scales quite well. Not sure about nix reading that much data though. I already thought about splitting it into multiple files... |
I first built the out-of-tree source support from Cargo workspaces. This had the advantage and the disadvantage of resolving the crate versions over all out-of-tree sources. See discussion in #102.
The |
Lock files are no longer merged by generated a Cargo workspace but by crate2nix itself. There is `tools.nix` support but it is still a little weird.
Interesting enough, I get a
|
The "workspace-less" out-of-tree sources support is ready for testing. Unfortunately, some of the crates that you wanted to test, fail to build. It is not impossible that I introduced an error with my changes. It is also possible that they fail to build individually. |
I can try some other ones. |
Some where about needing the nightly compiler, some were about missing native dependencies (solvable with overrides hopefully). |
I tried with
There is one thing that bugs me a bit however. To build rust packages we not have potentially 3 locations to touch:
The other problem is that we currently have no way of specifying patches. In an ideal world one could have a derivation file that were
crate2nix would it could call it like that to get the source
After building the source it could update the workspaceMember as before. Does this sound reasonable to you? This way we don't need special support for any fetcher logic + patch logic we have in nixpkgs. |
I now you like having your builtin prefetcher to not having to manually calculating checksums. However we have already more advanced tools for that like https://github.com/ryantm/nixpkgs-update or https://github.com/Mic92/nix-update that can handle way more than |
Hi @Mic92, I think that automatic updates would be awesome. Let's optimize the flow! I can't immediately see what requirements a package has to fulfill to be automatically updateable. In the case of rust, the "auto-update" should be on the root package with its E.g. with We could hook this into the update script mechanism. (I haven't dabbled with that before) It would help me, if you could tell me what "interface" or "package format" I can probably write the rust-specific glue if I know how it should look like. |
@Mic92 also, did you see my email about a VC? |
@kolloch do you still have time to work on this? If not we maybe should just describe the design we discussed and hope that someone else from the community can help on this. |
There are crates without lock files, like |
(I'm assuming that the new Is there a best practice here for how to use this feature when upstream doesn't include a
Should I submit a PR to add a command-line flag to tell |
If you use
crate2nix
with your own project, you can either use atools.nix
based workflow in whichCargo.nix
is generated in a derivation and imported. Or you can pregenerate yourCargo.nix
file if you prefer or using git with sub modules.If you want to package a crate which source is not in the tree but that you fetch with a derivation, only the tools option is currently convenient. Pregeneration of the source is not really supported.
I propose that
crate2nix
:crate-src.nix
file that evaluates to a derivation fetching the sources.crate-src.nix
and expect theCargo.lock
/Cargo.toml
file in the retrieved source.Cargo.nix
files and thecrate-hashes.json
files are stored in the same file as the sources.The text was updated successfully, but these errors were encountered: