remove references to crate2nix other than a link to its docs
This commit is contained in:
parent
618d8e6a62
commit
e369d78b70
|
@ -648,99 +648,13 @@ buildPythonPackage rec {
|
||||||
|
|
||||||
When run, `cargo build` produces a file called `Cargo.lock`,
|
When run, `cargo build` produces a file called `Cargo.lock`,
|
||||||
containing pinned versions of all dependencies. Nixpkgs contains a
|
containing pinned versions of all dependencies. Nixpkgs contains a
|
||||||
tool called `crate2Nix` (`nix-shell -p crate2nix`), which can be used
|
tool called `crate2Nix` (`nix-shell -p crate2nix`), which can be
|
||||||
to turn a `Cargo.lock` into a Nix expression.
|
used to turn a `Cargo.lock` into a Nix expression. That Nix
|
||||||
|
expression calls `rustc` directly (hence bypassing Cargo), and can
|
||||||
|
be used to compile a crate and all its dependencies.
|
||||||
|
|
||||||
That Nix expression calls `rustc` directly (hence bypassing Cargo),
|
See [`crate2nix`'s documentation](https://github.com/kolloch/crate2nix#known-restrictions)
|
||||||
and can be used to compile a crate and all its dependencies. Here is
|
for instructions on how to use it.
|
||||||
an example for a minimal `hello` crate:
|
|
||||||
|
|
||||||
```ShellSession
|
|
||||||
$ cargo new hello
|
|
||||||
$ cd hello
|
|
||||||
$ cargo build
|
|
||||||
Compiling hello v0.1.0 (file:///tmp/hello)
|
|
||||||
Finished dev [unoptimized + debuginfo] target(s) in 0.20 secs
|
|
||||||
$ carnix -o hello.nix --src ./. Cargo.lock --standalone
|
|
||||||
$ nix-build hello.nix -A hello_0_1_0
|
|
||||||
```
|
|
||||||
|
|
||||||
Now, the file produced by the call to `carnix`, called `hello.nix`, looks like:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
# Generated by carnix 0.6.5: carnix -o hello.nix --src ./. Cargo.lock --standalone
|
|
||||||
{ stdenv, buildRustCrate, fetchgit }:
|
|
||||||
let kernel = stdenv.buildPlatform.parsed.kernel.name;
|
|
||||||
# ... (content skipped)
|
|
||||||
in
|
|
||||||
rec {
|
|
||||||
hello = f: hello_0_1_0 { features = hello_0_1_0_features { hello_0_1_0 = f; }; };
|
|
||||||
hello_0_1_0_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate {
|
|
||||||
crateName = "hello";
|
|
||||||
version = "0.1.0";
|
|
||||||
authors = [ "pe@pijul.org <pe@pijul.org>" ];
|
|
||||||
src = ./.;
|
|
||||||
inherit dependencies buildDependencies features;
|
|
||||||
};
|
|
||||||
hello_0_1_0 = { features?(hello_0_1_0_features {}) }: hello_0_1_0_ {};
|
|
||||||
hello_0_1_0_features = f: updateFeatures f (rec {
|
|
||||||
hello_0_1_0.default = (f.hello_0_1_0.default or true);
|
|
||||||
}) [ ];
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
In particular, note that the argument given as `--src` is copied
|
|
||||||
verbatim to the source. If we look at a more complicated
|
|
||||||
dependencies, for instance by adding a single line `libc="*"` to our
|
|
||||||
`Cargo.toml`, we first need to run `cargo build` to update the
|
|
||||||
`Cargo.lock`. Then, `crate2nix` needs to be run again, and produces the
|
|
||||||
following nix file:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
# Generated by carnix 0.6.5: carnix -o hello.nix --src ./. Cargo.lock --standalone
|
|
||||||
{ stdenv, buildRustCrate, fetchgit }:
|
|
||||||
let kernel = stdenv.buildPlatform.parsed.kernel.name;
|
|
||||||
# ... (content skipped)
|
|
||||||
in
|
|
||||||
rec {
|
|
||||||
hello = f: hello_0_1_0 { features = hello_0_1_0_features { hello_0_1_0 = f; }; };
|
|
||||||
hello_0_1_0_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate {
|
|
||||||
crateName = "hello";
|
|
||||||
version = "0.1.0";
|
|
||||||
authors = [ "pe@pijul.org <pe@pijul.org>" ];
|
|
||||||
src = ./.;
|
|
||||||
inherit dependencies buildDependencies features;
|
|
||||||
};
|
|
||||||
libc_0_2_36_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate {
|
|
||||||
crateName = "libc";
|
|
||||||
version = "0.2.36";
|
|
||||||
authors = [ "The Rust Project Developers" ];
|
|
||||||
sha256 = "01633h4yfqm0s302fm0dlba469bx8y6cs4nqc8bqrmjqxfxn515l";
|
|
||||||
inherit dependencies buildDependencies features;
|
|
||||||
};
|
|
||||||
hello_0_1_0 = { features?(hello_0_1_0_features {}) }: hello_0_1_0_ {
|
|
||||||
dependencies = mapFeatures features ([ libc_0_2_36 ]);
|
|
||||||
};
|
|
||||||
hello_0_1_0_features = f: updateFeatures f (rec {
|
|
||||||
hello_0_1_0.default = (f.hello_0_1_0.default or true);
|
|
||||||
libc_0_2_36.default = true;
|
|
||||||
}) [ libc_0_2_36_features ];
|
|
||||||
libc_0_2_36 = { features?(libc_0_2_36_features {}) }: libc_0_2_36_ {
|
|
||||||
features = mkFeatures (features.libc_0_2_36 or {});
|
|
||||||
};
|
|
||||||
libc_0_2_36_features = f: updateFeatures f (rec {
|
|
||||||
libc_0_2_36.default = (f.libc_0_2_36.default or true);
|
|
||||||
libc_0_2_36.use_std =
|
|
||||||
(f.libc_0_2_36.use_std or false) ||
|
|
||||||
(f.libc_0_2_36.default or false) ||
|
|
||||||
(libc_0_2_36.default or false);
|
|
||||||
}) [];
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Here, the `libc` crate has no `src` attribute, so `buildRustCrate`
|
|
||||||
will fetch it from [crates.io](https://crates.io). A `sha256`
|
|
||||||
attribute is still needed for Nix purity.
|
|
||||||
|
|
||||||
### Handling external dependencies {#handling-external-dependencies}
|
### Handling external dependencies {#handling-external-dependencies}
|
||||||
|
|
||||||
|
@ -848,21 +762,6 @@ general. A number of other parameters can be overridden:
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
### Features {#features}
|
|
||||||
|
|
||||||
One can also supply features switches. For example, if we want to
|
|
||||||
compile `diesel_cli` only with the `postgres` feature, and no default
|
|
||||||
features, we would write:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
(callPackage ./diesel.nix {}).diesel {
|
|
||||||
default = false;
|
|
||||||
postgres = true;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Where `diesel.nix` is the file generated by Carnix, as explained above.
|
|
||||||
|
|
||||||
### Setting Up `nix-shell` {#setting-up-nix-shell}
|
### Setting Up `nix-shell` {#setting-up-nix-shell}
|
||||||
|
|
||||||
Oftentimes you want to develop code from within `nix-shell`. Unfortunately
|
Oftentimes you want to develop code from within `nix-shell`. Unfortunately
|
||||||
|
|
Loading…
Reference in a new issue