add rust template
This commit is contained in:
60
templates/rust/flake.nix
Normal file
60
templates/rust/flake.nix
Normal file
@@ -0,0 +1,60 @@
|
||||
{
|
||||
description = "Rust-Nix";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/unstable";
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
crate2nix = {
|
||||
url = "github:nix-community/crate2nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = inputs @ {
|
||||
crate2nix,
|
||||
flake-utils,
|
||||
nixpkgs,
|
||||
rust-overlay,
|
||||
...
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system: let
|
||||
# Overlay pkgs with rust-bin
|
||||
overlays = [(import rust-overlay)];
|
||||
pkgs = import nixpkgs {
|
||||
inherit system overlays;
|
||||
};
|
||||
|
||||
# Use rust-bin to generate the toolchain from rust-toolchain.toml
|
||||
rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
||||
|
||||
buildRustCrateForPkgs = pkgs:
|
||||
pkgs.buildRustCrate.override {
|
||||
rustc = rust-toolchain; # Use rustc from toolchain
|
||||
cargo = rust-toolchain; # Use cargo from toolchain
|
||||
};
|
||||
|
||||
# Cargo.nix for IFD
|
||||
generatedCargoNix = crate2nix.tools.${system}.generatedCargoNix {
|
||||
name = "rustnix";
|
||||
src = ./.;
|
||||
};
|
||||
|
||||
cargoNix = import generatedCargoNix {
|
||||
inherit pkgs buildRustCrateForPkgs;
|
||||
};
|
||||
in {
|
||||
packages = rec {
|
||||
hello = cargoNix.rootCrate.build;
|
||||
default = hello;
|
||||
};
|
||||
devShell = pkgs.mkShell {
|
||||
buildInputs = [rust-toolchain];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user