use flake-parts in rust template

This commit is contained in:
2026-08-18 13:18:13 +02:00
parent 85a45a3078
commit e95765eb10
3 changed files with 31 additions and 18 deletions
+2
View File
@@ -11,6 +11,8 @@ fi
watch_file nix/** watch_file nix/**
watch_file -- **/*.nix watch_file -- **/*.nix
watch_file Cargo.toml
watch_file rust-toolchain.toml
# Adding files to git includes them in a flake # Adding files to git includes them in a flake
# But it is also a bit much reloading. # But it is also a bit much reloading.
# watch_file .git/index .git/HEAD # watch_file .git/index .git/HEAD
+28 -17
View File
@@ -1,13 +1,13 @@
{ {
description = "Rust-Hello"; description = "Rust-Package";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
rust-overlay = { rust-overlay = {
url = "github:oxalica/rust-overlay"; url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
flake-utils.url = "github:numtide/flake-utils";
crate2nix = { crate2nix = {
url = "github:nix-community/crate2nix"; url = "github:nix-community/crate2nix";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@@ -15,20 +15,25 @@
}; };
outputs = inputs @ { outputs = inputs @ {
flake-parts,
crate2nix, crate2nix,
flake-utils,
nixpkgs,
rust-overlay, rust-overlay,
... ...
}: }:
flake-utils.lib.eachDefaultSystem ( flake-parts.lib.mkFlake {inherit inputs;} {
system: let systems = [
# Overlay pkgs with rust-bin "aarch64-linux"
overlays = [(import rust-overlay)]; "aarch64-darwin"
pkgs = import nixpkgs { "x86_64-darwin"
inherit system overlays; "x86_64-linux"
}; ];
perSystem = {
pkgs,
system,
self',
...
}: let
# Use rust-bin to generate the toolchain from rust-toolchain.toml # Use rust-bin to generate the toolchain from rust-toolchain.toml
rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
@@ -48,14 +53,20 @@
inherit pkgs buildRustCrateForPkgs; inherit pkgs buildRustCrateForPkgs;
}; };
in { in {
packages = rec { # Overlay pkgs with rust-bin
hello = cargoNix.rootCrate.build; _module.args.pkgs = import inputs.nixpkgs {
default = hello; inherit system;
overlays = [(import rust-overlay)];
}; };
devShell = pkgs.mkShell { packages = {
hello = cargoNix.rootCrate.build;
default = self'.packages.hello;
};
devShells.default = pkgs.mkShell {
buildInputs = [rust-toolchain]; buildInputs = [rust-toolchain];
}; };
} };
); };
} }
+1 -1
View File
@@ -1,3 +1,3 @@
[toolchain] [toolchain]
channel = "1.85.0" channel = "1.96.0"
components = [ "rustfmt", "rustc-dev", "rust-analyzer", "rust-src"] components = [ "rustfmt", "rustc-dev", "rust-analyzer", "rust-src"]