-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #359
- Loading branch information
Showing
2 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
docs/src/content/docs/00_guides/80_using_a_rust_overlay.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
title: Using a Rust overlay | ||
--- | ||
|
||
It's possible to use a Rust overlay such as `rust-overlay` with `crate2nix`. | ||
This can be used for pinning the Rust toolchain version, or to use a newer toolchain version than is available in Nixpkgs. | ||
|
||
In a flake with flake-parts: | ||
|
||
```nix | ||
# flake.nix | ||
{ | ||
# ... | ||
inputs = { | ||
flake-parts = { | ||
url = "github:hercules-ci/flake-parts"; | ||
inputs.nixpkgs-lib.follows = "nixpkgs"; | ||
}; | ||
crate2nix.url = "github:nix-community/crate2nix"; | ||
# ... | ||
}; | ||
outputs = | ||
inputs @ { self | ||
, nixpkgs | ||
, flake-parts | ||
, rust-overlay | ||
, crate2nix | ||
, ... | ||
}: | ||
flake-parts.lib.mkFlake { inherit inputs; } { | ||
systems = [ | ||
"x86_64-linux" | ||
"aarch64-linux" | ||
"x86_64-linux" | ||
"aarch64-darwin" | ||
]; | ||
perSystem = { system, lib, inputs', ... }: | ||
let | ||
pkgs = import nixpkgs { | ||
inherit system; | ||
overlays = [ rust-overlay.overlays.default ]; | ||
}; | ||
buildRustCrateForPkgs = | ||
crate: | ||
pkgs.buildRustCrate.override { | ||
rustc = pkgs.rust-bin.stable.latest.default; | ||
cargo = pkgs.rust-bin.stable.latest.default; | ||
}; | ||
generatedCargoNix = inputs.crate2nix.tools.${system}.appliedCargoNix { | ||
name = "rustnix"; | ||
src = ./.; | ||
}; | ||
cargoNix = import generatedCargoNix { | ||
inherit pkgs buildRustCrateForPkgs; | ||
}; | ||
in | ||
rec { | ||
checks = { | ||
rustnix = cargoNix.rootCrate.build.override { | ||
runTests = true; | ||
}; | ||
}; | ||
packages = { | ||
rustnix = cargoNix.rootCrate.build; | ||
default = packages.rustnix; | ||
}; | ||
}; | ||
}; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters