The last rust flake I will ever create (wink)
- Nix 100%
|
|
||
|---|---|---|
| .forgejo/workflows | ||
| nix | ||
| .gitignore | ||
| flake.lock | ||
| flake.nix | ||
| README.md | ||
| renovate.json | ||
nix-rust
Note: this documentations is work in progress. It mainly expalins the basics but you stil have to look into the nix code.
This projekt tries to simplify the rust toolchain for nix. It provides:
- a build option (
lib.buildRustPackage) which wraps around crane - a shell option (
lib.mkRustShell) which provides the same rust toolchain as the builder
Additionally it provides pre-made toolchains for different use-cases:
- android
- wasm
- esp targets
- ariel
Usage
Add this projekt as a flake input:
# flake.nix
{
inputs = {
nix-rust.url = "git+https://git.solarpunk.social/solarpunk-kollektiv-dd/nix-rust.git";
nix-rust.inputs.nixpkgs.follows = "nixpkgs";
};
}
Now you can use the lib functions from nix-rust in your code.
Create a devShell
You can use nix-rust.lib.shell.mkRustShell to create a rust devShell.
# flake.nix
{
outputs.devShells.default."x86_64-linux" = rust-nix.shell.mkRustShell {
system = "x86_64-linux";
base = "nativeWithOpenssl";
};
}
| Option | Description | Default |
|---|---|---|
| system | nixpkgs system for this devShell | "x86_64-linux" |
| extraDescription | additionaly devShell description | "" |
| extraPackages | additionaly packages accessibly in the devShell (besides the rust toolchain) | [] |
| extraShellHook | bash code to execute on shell-enter | "" |
| base | The base devShell to use. These are a combination of two parts "", where toolchain is one of native,android,wasm and tooling is one of Base,WithOpenssl,BevyX11,BevyWayland. Note that not every combination necessarily makes sense. |
"nativeBase" |
| name | Name of the devShell. If set to null, the default devShell name will be used | null |
| extraRpathPackages | Packages that should be available as libaries to rust | extraPackages |
Create a package
You can use nix-rust.lib.build.buildRustPackage to create a nix package out of your rust code.
# flake.nix
{
outputs.packages.default."x86_64-linux" = nix-rust.build.buildRustPackage {
inherit pkgs;
name = "my-programm";
src = ./.;
cargoLock = ./Cargo.lock;
cargoToml = ./Cargo.toml; # version will be derived from TOML
};
}
| Option | Description | Default |
|---|---|---|
| pkgs | nixpkgs to use | no default |
| src | Rust source code | no default |
| cargoToml | Nix path to a cargo.toml containing the project name & version |
no default |
| rust | nix-rust rust toolchain to use |
nix-rust.packages.${system}.buildRust |
| version | Version of the package | version from cargo.toml (if specified) |
| pname | Name of the package | project name from cargo.toml (if specified) |
| binaryArgs | Arguments that should be passed only to craneLib.buildDepsOnly |
{ } |
| dependencyArgs | Arguments that should be passed only to craneLib.buildPackage |
{ } |
Additionally options will be passed to craneLib.buildPackage.