rebuild only changed crates in CI with crate2nix and nix
APACHE-2.0 License
Bot releases are visible (Hide)
340 make crate2nix
compatible
with the lock file changes from rust 1.77.x.
Move sources into /build/sources to maximize compatibility.
Published by kolloch 6 months ago
The usual internal version updates but there is more!
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/!
tools
as flake attributeDo 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.
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.
shell.nix
via flake-compat. @kolloch
pkgs.callPackage
-compatible default.nix
for the crate2nix
binary. @kolloch
Tests and some utilities are still working flake-less but use the flake inputs by default.
Published by kolloch 10 months ago
Published by kolloch 12 months ago
foo?/bar
feature selectionsConditional 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).
buildRustCrate
parameterThis was previously deprecated.
callPackage
not raw import
as the recommended methodWith buildRustCrate
removed, this is now possible without running into
issues.
Previously only renamed dependencies
and build-dependencies
worked.
Now renamed dev-dependencies
work also.
Thank you @Fuuzetsu!
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 cfg
reosolution.
Support custom cfg(target_family = "whatever")
dependencies.
tools.nix
) for Nixpkkgs 22.11Published by kolloch over 3 years ago
Warning: This release does not work on Mac OS with a recent nixpkgs
. Help wanted.
Warning: the buildRustCrate
argument will be removed soon.
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, ..
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}".build
The 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!
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 the note
here.
Thank you @pandaman64!
This fixes the following isues:
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 +e
option 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!
Published by kolloch over 3 years ago
Help needed! I don't have the resources to meaningfully advance this project. Thankyou 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, ..
root_crate
and workspace_members
aliases in the generatedCargo.nix
files.cargo test
does. Thank you, @symphorien!direnv
support in the source. Thanks, @Mic92!stdenv.lib
. Thanks, @cole-h!Published by kolloch over 4 years ago
Organizational: @andir is now an additional official maintainer of crate2nix
. Welcome!
Breaking change:
nixpkgs-unstable
. On the upside, crates in sub directories of git repositories will now work!New features:
testInputs
to test execution. This allows users to add buildInputs
to 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).Under the hood:
crate2nix
itself by disabling some features.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".
Published by kolloch over 4 years ago
New features and improvements:
cargo metadata
. This allows to includecdylib
. Thank you, @andir!defaultCrateOverrides
internal.
attribute path element. Formally, this is noThank 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.sh
now makes it easier to prepare your pull requests for review.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:
Published by kolloch almost 5 years ago
Issue #22 - Support renamed crates. Fixed in buildRustCrate
in nixpkgs and in crate2nix
by PR #24 @danieldk, thanks a lot!
This is especially awesome because the popular rand
crate recently made use of the "renamed crates" feature and therefore could not be build by buildRustCrate
/crate2nix
anymore.
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 in default.nix
of crate2nix
to 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:
Happy building and thank you for the prime bug reports!
Published by kolloch about 5 years ago
Don't use ´Cargo.toml´ but ´Cargo.nix´ as default output! Thank you, @tilpner!
Published by kolloch about 5 years ago
-n
/--nixpkgs-path
to "<nixpkgs>"
so that it works by default on NixOS AND Mac OS.Published by kolloch over 5 years ago
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.
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:
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 ...;
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.
I would really appreciate your thoughts. Please add comments to issue #8.
Published by kolloch over 5 years ago
Changes since 0.2.0:
Added comments to the generated nix build file to indicate which attributes are public and unlikely to change.
Published by kolloch over 5 years ago
Initial public release.
Published by kolloch over 5 years ago
nix-prefetch-url
might run again.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.
"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!