Generating Cargo.nix for multiple fetched sources
NOTE: This is work in progress, see #102, the interface might still change.
crate2nix
has convenient support for managing out-of-tree sources: It will
manage a nix-generated directory of the source roots for you.
crate2nix
will use the supplied Cargo.lock
files in the sources to generate
the binaries with the versions that the maintainers specified.
Demo
Starting from scratch with an empty directory:
Adding a crates.io dependency by name and version:
Adding a git dependency by URL and revision hash:
Listing all our sources:
This also shows the commands with which you could recreate your sources for convenience.
Generating Cargo.nix
, prefetching some indirect git dependencies:
Building the binaries:
Running the binaries:
Managing sources in crate2nix.json
Here are some examples for adding sources:
If crate2nix.json
does not exist yet, it will be created.
As always, you can have a look at all available options and commands by using
crate2nix source --help
, crate2nix source add --help
and so forth.
crate2nix source list
shows already configured sources.
crate2nix source remove ripgrep
removes the source named ripgrep
.
crate2nix generate
crate2nix generate
will generally just do the right thing and pick up
crate2nix.json file if necessary:
- Build a
crate-sources
directory with all of your sources. It uses a generatedcrate-sources.nix
in your project directory. - Call
cargo metadata
individually for all sources and concatenate the results.
What to check into version control
For building the binaries, Cargo.nix
is sufficient. But everyone regenerating
it will appreciate if you also check in
crate2nix.json
(the source configuration)crate-hashes.json
(the hashes for packages not in the lockfile)
The generated crate-sources*
files should go into .gitignore
or similar:
crate-sources*
crate-sources.nix
is the temporary nix expression to download the sources.crate-sources
is the temporary result symlink to the downloaded sources.
Feature resolution
Note that features in crate2nix
are resolved at build time so that every
dependency is build only with the features necessary for the specific binary.
This is probably what you want because it can prevent build problems. Even
though, features in rust are meant to be additive, in reality they are often
not.