CHANGELOG
Unreleased
Section titled “Unreleased”Breaking changes
Section titled “Breaking changes”-
#520: The command line interface now uses clap 4 instead of structopt and clap 2. All subcommands, flags and defaults stay the same, but:
- usage errors, e.g. an unknown or missing argument, now exit with status 2 instead of 1. Other errors still exit with status 1.
--helpoutput and error messages look different: there is nocrate2nix <version>header line any more, the usage line is headedUsage:instead ofUSAGE:, options are listed in definition order, and value names are upper case (e.g.--output <OUTPUT>).
Shell completions for
crate2nix completionsare generated byclap_complete. -
#439: The hashes of git dependencies on a branch, a tag or the default branch are now stored in
crate-hashes.jsonunder a key that contains the locked commit, e.g.name 1.0.0 (git+https://github.com/org/repo?branch=main#<commit>). Before, crate2nix kept using the hash of the old commit aftercargo updatemoved such a dependency to a new commit (or after switching to another tag with the same crate version), which broke the build with a hash mismatch. Existing entries without the commit are ignored, socrate2nix generateprefetches these dependencies once more and rewritescrate-hashes.json. Dependencies pinned withrev = "..."keep their keys. Withtools.nix(generatedCargoNix), a checked-incrate-hashes.jsonwith the old keys makes the build fail with a diff until it is regenerated. Hashes of git dependencies are also no longer reused for a crates.io dependency with the same name and version.
New features
Section titled “New features”-
#561 (based on #276 by Andrew Poelstra):
generatedCargoNixandappliedCargoNixtake an optionalcargoLockargument, aCargo.lockto use instead of the one insrc. This works for libraries without a checked-inCargo.lockand for testing one source against several lock files. See Using another Cargo.lock. -
#144 (in part):
runTestsalso takes a list of the kinds of tests to run, named after cargo’s target selection flags:"lib"(--lib),"bins"(--bins) and"tests"(--test '*'), e.g.runTests = [ "lib" "bins" ]to run only the unit tests.runTests = truestays[ "lib" "bins" "tests" ],runTests = [ ]runs no tests and unknown kinds are an evaluation error. Doctests ("doc") are not supported yet. The test executables in the test build’stests/are now named<target name>-<hash>like cargo names them, and the test build writestests.json, which records the target name and kind (lib,binortest) of each of them; the test runner picks the executables to run from it. The check that an integration test doesn’t have the name of a binary (#530) moved from the test runner to the test build. The test builds of tested crates change, so expect them to be rebuilt once. See Choosing which tests run. -
#482, #244, #196:
rootCrateand every entry ofworkspaceMembershave abuildTestsattribute that builds the crate’s test executables with itsdev-dependencieswithout running them, e.g. to run integration tests in a NixOS VM test. It is overridable likebuild, andbuild.override { buildTests = true; }gives the same derivation. Thetestderivation of a build withrunTestsexposes the same test executables astest.testCrate. Thank you, @emanueljg! See Building the test binaries without running them. -
crate2nix ships its own variant of nixpkgs’
buildRustCrate: a copy of nixpkgs’pkgs/build-support/rust/build-rust-cratefrom a pinned revision (currently without changes), innix/build-rust-cratewith a script to update it. It is a drop-in replacement forpkgs.buildRustCrateand the base for upcoming features that need changes tobuildRustCrate. It is opt-in for now: passbuildRustCrateForPkgs = crate2nix.lib.buildRustCrateForPkgs(orcrate2nix.tools.${system}.buildRustCrateForPkgs, orbuildRustCrateForPkgsoftools.nix) to aCargo.nixor toappliedCargoNix(which takes the new argumentbuildRustCrateForPkgs). Both keep usingpkgs.buildRustCrateby default;appliedCargoNixwill switch to crate2nix’sbuildRustCrateonce it has its first own change (e.g. doctests). Everything works with both, but future features that need crate2nix’sbuildRustCratewill fail with a clear error without it. See crate2nix’s buildRustCrate. -
#513: Opt-in workspace feature unification: with the new
Cargo.nixargumentfeatureUnification = "workspace", the features of all workspace members are resolved together, so that the members share one build of each dependency (and their test builds another one), like cargo’sresolver.feature-unification = "workspace". The default,"package", keeps resolving each member on its own and gives the same derivations as before. See Feature unification in workspaces. -
#542, #490, #496: Opt-in forwarding of each crate’s
license,repository, andhomepagefrom itsCargo.tomlinto the generatedCargo.nix, for consumers such as SBOM generators. Enable it withcrate2nix generate --crate-metadataor"crateMetadata": trueincrate2nix.json; see Generate Cargo.nix manually. Thank you, @charludo and @ksil! -
#538 (based on #497 by Varun Shah):
allWorkspaceMembersevaluates all members over one shared table of crate derivations, instead of instantiating the crates they share once per member, which makes evaluating large workspaces much faster. The newallWorkspaceMembers.members.<name>gives the derivation of each member, identical toworkspaceMembers.<name>.build, for flakes that expose members separately. See Building all or many workspace members. -
#540: With
featureUnification = "workspace", the builds of all workspace members share their crate derivations, lazily: evaluating everyworkspaceMembers.<name>.buildof a 300-member workspace takes 0.5 s instead of 13 s. The derivations are unchanged, except that a test build whose dev-dependency depends back on the tested member now evaluates (the dev-dependency gets the member without its dev-dependencies) instead of recursing infinitely. The docs now recommendfeatureUnification = "workspace"for workspaces that are built as a whole. -
#543 (based on #495 by kkovalchick): Features are resolved like cargo’s feature resolver “2” when the project uses it, which edition 2021 and later imply: build dependencies, proc-macros and the crates they depend on get their own features, so that features only needed at build time no longer leak into the target build.
crate2nix generatereads the resolver fromCargo.tomland renders it as the default of the newCargo.nixargumentresolverVersion. Regenerating theCargo.nixof such a project changes the derivations of the crates used in both roles with different features, and of the crates depending on them. The newmergePackageFeaturesByKindandmergeWorkspaceFeaturesByKindreturn the features per kind; with resolver “2” or later,debugCrate’smergedPackageFeaturesdoes, too. See Feature resolver. -
Issue #339: The
crateConfigargument ofCargo.nix, which was accepted but ignored, now addsbuildRustCratearguments to every crate, e.g.crateConfig = { extraRustcOpts = [ "-C" "debuginfo=1" ]; codegenUnits = 16; }. Flags and inputs such asextraRustcOptsandbuildInputsare appended to the crate’s, other values replace them. It can also be a function of a crate’sbuildRustCratearguments, for settings per crate. Without the argument, acrate-config.nixnext toCargo.nixis used if it exists. See Settings for all crates. -
#479: JSON mode (
lib/build-from-json.nix) takes acrateConfigargument, too. In both modes, acrateConfigcan drop the dependencies of a cargo-hakari workspace-hack crate, so that members no longer depend on crates they do not use: see Workspace-hack crates. Thank you, @lovesegfault, for the idea! -
#287 (based on #405 by @giodamelio and #406 by @lelongg): New
Cargo.nixarguments for the sources of local crates:localCratesFilesetchooses the files of each local crate as alib.fileset, given the crate’s directory, name, version and enabled features. The default is exported asdefaultLocalCratesFilesetbyCargo.nixandtools.nix.localCratesSrcchooses the directory that local crates come from, e.g.localCratesSrc = path: mySrc + path. See Filtering local sources. Thank you, @giodamelio and @lelongg! -
#347: Faster
generatedCargoNix/appliedCargoNix: they cleansrcwith the default filter for local crates, and with the newmanifestsOnly = true, the input ofcrate2nix generateonly contains the manifests, lock files, crate2nix configuration and empty placeholders for target roots and other files thatcargo metadatareads. Editing a source file then doesn’t generateCargo.nixagain, and the local crates are built from the originalsrcvialocalCratesSrc.manifestsOnlyis off by default and planned to become the default in a future release. They also takelocalCratesFileset, whichappliedCargoNixpasses on toCargo.nix. See Faster IFD. The cleaning removes the same files from the input ofcrate2nix generateas from the sources of local crates, e.g. also directories namedtargetat any depth, socrate2nix generatedoesn’t find crates in such directories anymore.
-
#563 (based on #266 by Ben Wolsieffer): Crate overrides set with
buildRustCrateForPkgs = pkgs: pkgs.buildRustCrate.override { defaultCrateOverrides = ...; }are now applied when cross-compiling with nixpkgs 25.05 or older. When cross-compiling, these nixpkgs releases passCargo.nixa copy ofpkgs.defaultCrateOverrides(it is “spliced” bycallPackage).Cargo.nixtook the copy for custom overrides and passed it tobuildRustCrate, in place of the user’s overrides. Without custom overrides, crates for the build platform (build dependencies, proc-macros and their dependencies) now also get the crate overrides ofpkgs.buildPackagesinstead of those ofpkgs. The same applies tolib/build-from-json.nix. Thank you, @lopsided98, for finding this and the first fix! -
#547: The debugging helper
debug.internal.diffedDefaultPackageFeatures(fromdiffDefaultPackageFeatures) works again. It read attributes that did not exist and so always reported no feature differences. It now compares crate2nix’s resolved features with cargo’sresolvedDefaultFeatures, usesrootFeatures(or the newfeaturesargument) instead of always[ "default" ], and lists both sides indifferentFeatures. -
#430 by Domen Kožar:
generatedCargoNix(and the other IFD helpers oftools.nix) can now handle git dependencies whose crate uses workspace inheritance (version.workspace = true,serde = { workspace = true, features = [...] },lints.workspace = true, …), fixing #311. Git crates are vendored without their workspace root, so, likecargo vendor, the vendored crate now gets a standaloneCargo.tomlwith the inherited values filled in from the closest workspace root (orpackage.workspace). Features are added to those of the workspace,optionalcomes from the member, and relative paths are rebased onto the crate directory. -
#403 by Sam Pointon: Dependencies under
cfg(target_env = "...")are selected for the target’s actualtarget_env, as in Cargo (fixes #402). Before,Cargo.nixassumedtarget_env = "gnu"on every platform, e.g. also for musl, macOS ("") and WASI ("p1"), and--format jsondid not match"p1"or"". crate2nix takestarget_envfrom nixpkgs’rust.platform.envand, with older nixpkgs that lack it, derives it from the platform’s ABI. -
#549: JSON mode (
crate2nix generate --format jsonwithlib/build-from-json.nix) builds git dependencies that live in a subdirectory of their repository (fixes #492). The JSON records the crate’s directory in the repository aspathin its git source, andbuild-from-json.nixbuilds the crate there, inside the whole checkout, as Cargo does. Ifpathis missing, e.g. in JSON generated from vendored sources,buildRustCratesearches the repository for the crate’sCargo.toml, as with the generatedCargo.nix; regenerate older JSON to getpath. Git dependencies are now also fetched with their submodules, as Cargo does. -
#554: Crates are compiled with more of the environment variables that cargo sets:
CARGO, the path of the cargo binary, which build scripts and proc-macros such as sqlx’s run (fixes #409). It is thecargothatbuildRustCrateuses, e.g. one from a Rust toolchain overlay.CARGO_CRATE_NAME(partly addresses #158). It is the library’s name for all targets of a package, see Known restrictions.CARGO_PKG_DESCRIPTION, with--crate-metadata(fixes #356), which now also forwards thedescriptionfromCargo.toml.
--format jsonbuilds now also getCARGO_PKG_LICENSE,CARGO_PKG_REPOSITORYandCARGO_PKG_HOMEPAGEwith--crate-metadata. Quotes, backticks and$in these values no longer break the build. All crates’ derivations change, so expect a one-time rebuild. -
#552: Dependencies under
[target.'cfg(target_has_atomic = "64")'.dependencies](and the other widths) are enabled on platforms with atomics of that width, as in Cargo (fixes #469). Before, the condition was always false, which broke e.g. arkworks 0.5.makeDefaultTargetnow setshas_atomicto the widths rustc reports for the platform, e.g.[ "8" "16" "32" "64" "ptr" ]for x86_64-linux. nixpkgs does not know these, so they are derived from the CPU (or, like rustc, frommax-atomic-width,target-pointer-widthandatomic-casof a custom target spec); passextraTargetFlags.has_atomicif they differ fromrustc --print cfg --target <target>for your target. The JSON output (lib/build-from-json.nix) evaluatestarget_has_atomicthe same way, but has no override. -
#555: Dependencies under
cfg(target_arch = "x86")are now enabled for i686 (and i386, i486, i586) targets: crate2nix used nixpkgs’ CPU name"i686"where rustc says"x86".aarch64_be,mipselandpowerpcleare mapped to rustc’saarch64,mipsandpowerpcas well. JSON mode (lib/build-from-json.nix) used the raw CPU name, so it also missedtarget_archdependencies on ARM,mips64elandpowerpc64le; it now uses the same mapping. Fixes #183. -
#546 (based on #486 by Varun Shah): Crates that declare no
defaultfeature no longer get--cfg feature="default"when they are depended on with default features (or built as a root withrootFeatures = [ "default" ]), as in Cargo (fixes #485). Before, such a crate was built twice if it was also reached withdefault-features = false, and so was everything that depended on it. A crate that declares an emptydefault = []keepsdefaultwhen it is requested, and the generatedCargo.nixnow lists it asdefault = [ ];. The derivations of crates without adefaultfeature change, so expect a one-time rebuild. -
#539: Optional dependencies that a feature names as
dep:<name>no longer get an implicit feature<name>, as in Cargo. crate2nix added it whenever the dependency was enabled, and turned on the crate’s own feature of that name, if it had one: e.g. reqwest 0.13’srustls(and with it aws-lc-rs) when onlyrustls-no-providerwas asked for. Builds may lose such spurious features, e.g.--cfg feature="memchr"on aho-corasick. -
#544: The same fix for
--format json: an explicit feature that shares an optional dependency’s name no longer adds that dependency. -
#541: Forward the manifest’s
readmefield, sobuildRustCratesetsCARGO_PKG_READMEand build scripts that read it (e.g. rusqlite_migration’s) work (fixes #440). Most crates’ derivations change, so expect a one-time rebuild. -
#515: The dev shell of the
flake-binarytemplate now setsLIBRARY_PATH, so it can link Rust binaries on macOS. It no longer fails withld: library not found for -liconv. -
#516: On macOS,
cdylibanddylibcrates get their store path as install name, so binaries linked against them find them at runtime (#116). -
#530:
runTestsnow fails with an explanation when a binary target and an integration test have the same name, e.g.src/main.rsof cratefooandtests/foo.rs. buildRustCrate writes the test executables of both to the same file, so with current nixpkgs the integration test silently did not run. Rename the integration test to fix it. -
#494: JSON mode (
lib/build-from-json.nix): thebuildTestsof a workspace member takes its dependencies from the crate graph shared with the normal builds, instead of evaluating a graph of its own for every member, which makes evaluating the test builds of many members faster. The derivations are unchanged, except that a dev-dependency that depends back on the tested member now gets the member’s normal build, as with cargo, and no longer its test build, which recursed infinitely. Thank you, @emmakloe!
Internal
Section titled “Internal”- #522: crate2nix renders
Cargo.nixwith tera 2 instead of tera 1. It generates the sameCargo.nixas before. Errors while rendering a template are now reported with file, line and column instead of a debug dump.
0.15.0 (2026-01-28)
Section titled “0.15.0 (2026-01-28)”New features
Section titled “New features”- #366: Support for private registries. Thank you, @P-E-Meunier!
- #390: Allow selected toolchain in
generatedCargoNix. Thank you, @bengsparks! - #416: Add
extraTargetFlagsparameter for custom cfg conditions.
- #357: Use
mkDerivationwithsrcinstead ofrunCommandfor test derivation. - #372: Fix build-dependencies resolution when cross-compiling. Thank you, @pnmadelaine!
- #375: Fix cargo tests and clippy warnings. Thank you, @pnmadelaine!
- #388: Respect
fetchurlpassed via top-level Cargo.nix. Thank you, @weihanglo! - #391: Fix incorrect resolution of aliased git dependencies when multiple versions of the same package are referenced. Thank you, @hallettj!
- #407: Inherit the main crate’s
metawhen building with tests. Thank you, @jrobsonchase! - Fix parsing checksums from v1 manifests with latest cargo. Thank you, @hallettj!
- #394: Fix handling of git dependencies with wildcard workspace members and subcrates in nested directories. Thank you, @Pacman99!
Documentation
Section titled “Documentation”Internal
Section titled “Internal”- #414: Update flake inputs. Thank you, @jrobsonchase!
0.14.x - 0.14.1 (2024-06-30)
Section titled “0.14.x - 0.14.1 (2024-06-30)”Maintenance release with cross-compilation fixes, documentation improvements and removal of old workarounds.
-
#352:
rust.lib->stdenv.hostPlatform.rust- Always filter
srcusingfilterSource - Get rid of
dontStripfor Darwin as it’s no longer needed - Remove no longer needed
unsafeDiscardStringContextworkaround
-
#351: Set
--extra-experimental-features flakesinregenerate_cargo_nix.sh. -
#350: Document
targetFeaturesbetter.
0.13.x - 0.14.0 (2024-04-11)
Section titled “0.13.x - 0.14.0 (2024-04-11)”340 make crate2nix compatible
with the lock file changes from rust 1.77.x.
Move sources into /build/sources to maximize compatibility.
0.12.x - 0.13.0
Section titled “0.12.x - 0.13.0”The usual internal version updates but there is more!
Documentation as Github Page
Section titled “Documentation as Github Page”The old README.md had become very long and hard to navigate. Check out the new and shiny page at https://nix-community.github.io/crate2nix/!
- Create new Github Page. @kolloch
- Move most of the old content there. @kolloch
Export tools as flake attribute
Section titled “Export tools as flake attribute”Do you like to use import from derivation
so that you do not have to regenerate Cargo.nix on every dependency change?
The related convenience functions are now also available via the flake attribute “tools”:
# ... perSystem = { system, pkgs, lib, inputs', ... }: let cargoNix = inputs.crate2nix.tools.${system}.appliedCargoNix { name = "rustnix"; src = ./.; }; in rec { packages.default = cargoNix.rootCrate.build; };# ...Check out the documentation.
Flakify the crate2nix build itself
Section titled “Flakify the crate2nix build itself”Convert the pre-flake infrastructure step-by step to nix flakes, while attempting to preserve compatibility for non-flake users.
This is more of an internal change and should not affect the usage of crate2nix yet but a more flake friendly interface is planned.
- Convert flake.nix to flake.parts. @kolloch
- Use devshell for devShell. @kolloch
- Provide
shell.nixvia flake-compat. @kolloch - Provide an “old-school”
pkgs.callPackage-compatibledefault.nixfor thecrate2nixbinary. @kolloch
Tests and some utilities are still working flake-less but use the flake inputs by default.
0.11.x - 0.12.0
Section titled “0.11.x - 0.12.0”- Cross compilation fixes. Thank you, @flokli!
- Propagate crate links attribute. Thank you, @lblasc!
- Determine target vendor via nixpkgs function. Thank you, @jordanisaacs!
- Initial flake.nix for crate2nix. Thank you, @vleni!
0.10.x - 0.11.0
Section titled “0.10.x - 0.11.0”Support foo?/bar feature selections
Section titled “Support foo?/bar feature selections”Conditional features
are now supported. The feature selection foo?/bar will only enable the bar feature of the foo
dependency if that dependency would be enabled anyway (non-optional, or enabled by a different feature selection).
Remove buildRustCrate parameter
Section titled “Remove buildRustCrate parameter”This was previously deprecated.
Restore callPackage not raw import as the recommended method
Section titled “Restore callPackage not raw import as the recommended method”With buildRustCrate removed, this is now possible without running into
issues.
Finish renamed dependency support
Section titled “Finish renamed dependency support”Previously only renamed dependencies and build-dependencies worked.
Now renamed dev-dependencies work also.
Thank you @Fuuzetsu!
Better cross and platform-specific compilation support
Section titled “Better cross and platform-specific compilation support”-
Rust-style rather than Nixpkgs-style configs are used for
[target."some-config"]conditional Cargo sections. -
The nixpkgs Rust “lib” is used to implement the above and deduplicate other
cfgreosolution. -
Support custom
cfg(target_family = "whatever")dependencies.
Fix IFD support library (tools.nix) for Nixpkkgs 22.11
Section titled “Fix IFD support library (tools.nix) for Nixpkkgs 22.11”- See the comment inside there for details.
0.9.x - 0.10.0
Section titled “0.9.x - 0.10.0”Help needed! I don’t have the resources to meaningfully advance this project. Thank you for all the valuable contributions but I’d appreciate a co-maintainer who is motivated to put in some time into reviewing PRs, updating docs, fixing bugs, ..
Warning: This release does not work on Mac OS with a recent nixpkgs. Help wanted.
Warning: the buildRustCrate argument will be removed soon.
New “calling convention”
Section titled “New “calling convention””The recommended convention to use Cargo.nix files generated by crate2nix has
changed. Instead of callPackage you know should use import:
let cargo_nix = import ./Cargo.nix { inherit pkgs; };in cargo_nix.workspaceMembers."${your_crate_name}".buildThe reason is that the deprecated buildRustPackage argument gets automatically
supplied from pkgs.buildRustPackage by pkgs.callPackage. This causes problems
when cross compiling.
This was debugged by @symphorien, thank you!
New: Enable optional create feature if sub feature was enabled
Section titled “New: Enable optional create feature if sub feature was enabled”Enable a feature with the same name of an optional dependency, if the optional dependency is indirectly enabled by enabling one of its features.
This mimicks the behavior of Cargo which is explained in this note.
Thank you @pandaman64!
This fixes the following isues:
- #146 Features fail to contain optional dependencies that got enabled indirectly
- #182 Can’t build crate with dependency num 0.4.0
New: Customize test commands
Section titled “New: Customize test commands”Want to customize your test execution? Use the testPreRun and testPostRun
crate attributes (next to runTests, see
README.md). crate2nix executes the
bash snippets in testPreRun and testPostRun directly before and after the
actual test command, and in the same shell. Some example use-cases include:
-
Setting some environment variable that is needed for the test.
-
Setting (and then unsetting) the bash
set +eoption to not fail the derivation build even if a test fails. This is quite useful if your tests are not flaky and you want to cache failures.
Thank you @Fuuzetsu!
0.8.x - 0.9.0
Section titled “0.8.x - 0.9.0”Help needed! I don’t have the resources to meaningfully advance this project. Thank you for all the valuable contributions but I’d appreciate a co-maintainer who is motivated to put in some time into reviewing PRs, updating docs, fixing bugs, ..
Breaking changes
Section titled “Breaking changes”- Remove long deprecated
root_crateandworkspace_membersaliases in the generatedCargo.nixfiles.
Enhancements
Section titled “Enhancements”- Issue #83 Supporting depending on different versions of the same crate!
- Some strides towards cross-compilation support. Docs missing and would be appreciated! Thanks, @Ericson2314, @lopsided98!
- Experimental out-of-tree support — with no time to work further on it :(
Under the hood
Section titled “Under the hood”- Test execution is now closer to what
cargo testdoes. Thank you, @symphorien! - Better
direnvsupport in the source. Thanks, @Mic92! - Better support for upcoming nix 3.0. Thanks, @balsoft!
- tests: avoid building two versions of the same crate. Thanks, @andir!
- Remove usages of deprecated
stdenv.lib. Thanks, @cole-h!
0.7.x - 0.8.0
Section titled “0.7.x - 0.8.0”Organizational: @andir is now an additional official maintainer of crate2nix.
Welcome!
Breaking change:
- If you are building crates with git dependencies, you will now need to update
to a recent version of
nixpkgs-unstable. On the upside, crates in sub directories of git repositories will now work!
New features:
- Issue #53: Search for matching Cargo.toml for git dependencies.
- Running tests is now documented in the README.
- Add
testInputsto test execution. This allows users to addbuildInputsto the test execution. This might be required as during test execution external programs will be called on generated output or in cases where the rust application is just a wrapper around some other tool (in some way or another). - Issue #47 Shorter package IDs: Use the crate name or the crate name together with the version as package ID if that is unique. That shortens the generated files, makes them more readable and also strips local paths from the package IDs in most cases. The last point means that you do not have an unncessary diff in you generated Cargo.nix because someone else was regenerating it.
Under the hood:
- Trimmed down the dependency tree of
crate2nixitself by disabling some features. - At least some smoke tests for debug functionality.
If you are interested in hacking on crate2nix and buildRustCrate: There are
now some convenience flags for the ./run_tests.sh script for offline mode and
running the tests against your own modified version of nixpkgs. Check out the
README section “Hacking on buildRustCrate in nixpkgs”.
0.6.x - 0.7.1
Section titled “0.6.x - 0.7.1”New features and improvements:
- Use hashes from Cargo.lock instead of prefetching when available. This should work for any crates.io dependency. :)
- Follow up to Issue #22 (and others) - Handling of “renamed crates”. Thanks a lot,@andir!
- Support for multiple binaries from the same crate. Thank you, @kristoff3r!
- Issue #34 - Support for git prefetching so that repositories with sub modules now work. Thank you, @cpcloud!
- Issue #65 - Reexpose
feature selection parameters from
cargo metadata. This allows to include dependencies in the generated build file which are not used for the default features. Or to exclude dependencies for features that you do not care about. - Issue #67 - Support for
additional lib types - in particular,
cdylib. Thank you, @andir! Write a rust library that is used from C code :) - Issue #18 - Optional crate unavailable Allows building packages that have multiple versions of the same dependency (with different targets). In particular the flate2 package now builds. Thank you, @cchalmers!
- Issue #37 - Conditional target expressions for dependencies can now also depend on features. Thank you, @cpcloud!
- Issue #42 - Some efficiency improvements to prevent stack overflows for projects with huge dependency trees. Thank you, @jamii! * Issue #90 There is a follow up to this: @nagisa was seeing super-linear instantiation counts and provided a flamegraph. @andir proposed a likely fix in nixpkgs. Thank you!
- Add fuchsia as an unsupported target (ef945396fcb700322b5b5f497a5d243950ed2513 ). Thank you, @jamii!
- Issue #94: The
defaultCrateOverridesargument to the build file has finally the desired effect again. - #75: Cleanly separate
internal API by
internal.attribute path element. Formally, this is no breaking change if it only effects private API but still. I will mitigate by allowing the old paths for a release and issue a warning.
Thank you to everyone who contributed with awesomely detailed issues, PRs or otherwise. You are amazing! Please let me know if I forgot something or forgot to give someone appropriate credit.
For contributors:
./run_tests.shnow makes it easier to prepare your pull requests for review.- Build artifacts for linux are now properly pushed to eigenvalue.cachix.org. Adding that cache with cachix will speed up your installations and builds. And it speeds up our CI builds via github actions. Shout out to @domenkozar and other cachix contributors.
- @alyssais contributed some fixes to the developer scripts, thank you!
Experimental and still undocumented:
cargo test-like test running support! Thank you very much for your great work, @andir!
Heads up! Feel free to discuss these planned changes in future releases with me:
- #77: New/better override behavior that
also allows overriding
buildRustCratemore easily. - #82: Use a new file name for
crate-hashes.jsonevery time to prevent merge issues. - #102: Convenient support for out-of-tree sources (e.g. for nixpkgs)
0.6.0 - 0.6.1
Section titled “0.6.0 - 0.6.1”Backported escaping fix for target expressions.
0.5.1 - 0.6.0
Section titled “0.5.1 - 0.6.0”-
Issue #22 - Support renamed crates. Fixed in
buildRustCratein nixpkgs and incrate2nixby PR #24 @danieldk, thanks a lot! This is especially awesome because the popularrandcrate recently made use of the “renamed crates” feature and therefore could not be build bybuildRustCrate/crate2nixanymore. -
Issue #15 - Support “overrideCrates” argument for modifying the derivation for a crate by name. Common use case, adding additional buildInputs. NixOS comes with
[defaultCrateOverrides](https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/rust/default-crate-overrides.nix)for some common packages already. This is what I use indefault.nixofcrate2nixto add a conditional dependency under Mac OS:cargo_nix.rootCrate.build.override {crateOverrides = defaultCrateOverrides // {cssparser-macros = attrs: {buildInputs = stdenv.lib.optionals stdenv.isDarwin [darwin.apple_sdk.frameworks.Security]; };};};Many thanks to @Profpatsch for pointing to the problem and analyzing it.
-
Issue #43 - Support conditional dependencies using “test” configuration:
[target.'cfg(test)'.dependencies]tracing = { version = "0.1.5", features = ["log"] }When building with
crate2nix, dependencies will not lead to an error anymore and will simply be ignored (since we do not have test support yet). Thanks to @andir for the nice minimal example!
Infrastructure:
- I moved the integration tests to tests.nix, they were in rust code before.
- I also now build every push with github actions, and cachix/cachix-action. A suggestion from @vbrandl in #44. Unfortunately, the rust crates are not cached yet, I think, because they are not in the closure of the result. The cachix caches is called “eigenvalue” for now (I might change that in the future).
0.5.0 - 0.5.1
Section titled “0.5.0 - 0.5.1”Don’t use ´Cargo.toml´ but ´Cargo.nix´ as default output! Thank you, @tilpner!
0.4.0 - 0.5.0
Section titled “0.4.0 - 0.5.0”Upgrading
Section titled “Upgrading”- The default output file changed to “./Cargo.toml”. Specify “-o ./default.nix” explicitly to retain the old default.
Resolved issues
Section titled “Resolved issues”- Issue #10 - Changing default
for
-n/--nixpkgs-pathto"<nixpkgs>"so that it works by default on NixOS AND Mac OS. - Issue #11 - Adding optional dependencies if any of their features is enabled.
- Issue #14 - Only overwrite output if explicitly specified as output file.
0.3.1 - 0.4.0
Section titled “0.3.1 - 0.4.0”Upgrading
Section titled “Upgrading”Please change references to root_crate to rootCrate.build and references to workspace_members.${crateName}
to workspaceMembers.${crateName}.build. The camel case attribute names are in line with the nixos style guide.
The .build suffix allows future versions of crate2nix to add other convenient features such as source tarball
packages, docker image derivations, … The old aliases still work but are deprecated.
Dynamic feature resolution
Section titled “Dynamic feature resolution”The enabled features for a crate now are resolved at build time! That means you can easily override them:
-
There is a “rootFeatures” argument to the generated build file which you can override when calling it from the command line:
Terminal window nix build -f ....nix --arg rootFeatures '["default" "other"]' rootCrate.build -
Or when importing the build file with “callPackage”:
let cargo_nix = callPackage ./Cargo.nix { rootFeatures = ["default" "other"]; };crate2nix = cargo_nix.rootCrate.build;in ...; -
Or by overriding them on the rootCrate or workspaceMembers:
let cargo_nix = callPackage ./Cargo.nix {};crate2nix = cargo_nix.rootCrate.build.override { features = ["default" "other"]; };in ...;
Internal: nix test runner
Section titled “Internal: nix test runner”For this release, I needed substantial amount of nix code so I created some nix unit tests. They are invoked by
cargo test like all other tests and live in the ./templates/nix/crate2nix/tests
directory.
Feedback: What is needed for a 1.0 release?
Section titled “Feedback: What is needed for a 1.0 release?”I would really appreciate your thoughts. Please add comments to issue #8.
0.3.0 - 0.3.1
Section titled “0.3.0 - 0.3.1”Bugfixes
Section titled “Bugfixes”- Issue #5: Support
libPathfor proc-macro crates.
Thank you @nuxeh for reporting this bug! Again :)
0.2.1 - 0.3.0
Section titled “0.2.1 - 0.3.0”Bugfixes
Section titled “Bugfixes”- Issue #4: Support for
libName!=crateName.
Thank you @nuxeh for reporting this bug!
Support for dependencies with git sources
Section titled “Support for dependencies with git sources”Example:
[dependencies]"crate2nix" = { git = "https://github.com/kolloch/crate2nix" }0.2.0 - 0.2.1
Section titled “0.2.0 - 0.2.1”- Added comments to the generated nix build file to indicate which attributes are public and unlikely to change.
0.1.0 - 0.2.0
Section titled “0.1.0 - 0.2.0”Bugfixes
Section titled “Bugfixes”- While the command line help said that the “crate hashes” would be stored in a file called “crate-hashes.json”, it
actually used the file “crate_hashes.json” by default. This release uses the documented name which means that
after the update
nix-prefetch-urlmight run again. - Issue #3: Do not depend on local channel configuration for shell anymore. Instead, we use a recent nixos-unstable because we still need a fix that’s not in stable.
Workspace Support
Section titled “Workspace Support”If crate2nix is applied to a workspace, the resulting nix-file will contain a top-level “workspace_members” attribute
set that refers the corresponding top-level crate derivations by name.
Target-specific dependencies
Section titled “Target-specific dependencies”“cfg(…)” expressions and target triplets such as “i686-pc-windows-gnu” are compiled into nix expressions. Support should be reasonable but incomplete because e.g. it does not work for processor features. Please let me know if this causes problems for you!
Initial public release.