Skip to content

Commit

Permalink
Add docs about custom toolchains
Browse files Browse the repository at this point in the history
  • Loading branch information
surma authored and kolloch committed Oct 30, 2024
1 parent bbc4b68 commit 1511224
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions docs/src/content/docs/00_guides/42_custom_toolchains.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: Custom Toolchains
---

One way to use a custom rust toolchain with `crate2nix` is to
import nixpkgs with an overlay for `rustc`.

Here is an example flake using [fenix]:

```nix
{
description = "containix";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/24.05";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
crate2nix.url = "github:nix-community/crate2nix";
};
outputs =
{
self,
nixpkgs,
flake-utils,
fenix,
crate2nix,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
toolchain = fenix.packages.${system}.stable.defaultToolchain;
pkgs = import nixpkgs {
inherit system;
overlays = [
(final: prev: {
rustc = toolchain;
cargo = toolchain;
})
];
};
crate2nix' = pkgs.callPackage (import "${crate2nix}/tools.nix") {};
cargoNix = crate2nix.appliedCargoNix {
name = "my-crate";
src = ./.;
};
in
{
packages = {
default = cargoNix.rootCrate.build;
};
}
);
}
```

[fenix]: https://github.com/nix-community/fenix

0 comments on commit 1511224

Please sign in to comment.