diff --git a/templates/_rust/.envrc b/templates/_rust/.envrc index 412cbef..d519bca 100644 --- a/templates/_rust/.envrc +++ b/templates/_rust/.envrc @@ -11,6 +11,8 @@ fi watch_file nix/** watch_file -- **/*.nix +watch_file Cargo.toml +watch_file rust-toolchain.toml # Adding files to git includes them in a flake # But it is also a bit much reloading. # watch_file .git/index .git/HEAD diff --git a/templates/_rust/flake.nix b/templates/_rust/flake.nix index 2d1b81a..b0d7853 100644 --- a/templates/_rust/flake.nix +++ b/templates/_rust/flake.nix @@ -1,13 +1,13 @@ { - description = "Rust-Hello"; + description = "Rust-Package"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; 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"; @@ -15,20 +15,25 @@ }; outputs = inputs @ { + flake-parts, 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; - }; + flake-parts.lib.mkFlake {inherit inputs;} { + systems = [ + "aarch64-linux" + "aarch64-darwin" + "x86_64-darwin" + "x86_64-linux" + ]; + perSystem = { + pkgs, + system, + self', + ... + }: let # Use rust-bin to generate the toolchain from rust-toolchain.toml rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; @@ -48,14 +53,20 @@ inherit pkgs buildRustCrateForPkgs; }; in { - packages = rec { - hello = cargoNix.rootCrate.build; - default = hello; + # Overlay pkgs with rust-bin + _module.args.pkgs = import inputs.nixpkgs { + 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]; }; - } - ); + }; + }; } diff --git a/templates/_rust/rust-toolchain.toml b/templates/_rust/rust-toolchain.toml index 535db1f..b74d279 100644 --- a/templates/_rust/rust-toolchain.toml +++ b/templates/_rust/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.85.0" +channel = "1.96.0" components = [ "rustfmt", "rustc-dev", "rust-analyzer", "rust-src"]