summaryrefslogtreecommitdiff
path: root/templates/rust/flake.nix
diff options
context:
space:
mode:
Diffstat (limited to 'templates/rust/flake.nix')
-rw-r--r--templates/rust/flake.nix56
1 files changed, 56 insertions, 0 deletions
diff --git a/templates/rust/flake.nix b/templates/rust/flake.nix
new file mode 100644
index 0000000..8a75f83
--- /dev/null
+++ b/templates/rust/flake.nix
@@ -0,0 +1,56 @@
+{
+ inputs = {
+ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+ flake-parts.url = "github:hercules-ci/flake-parts";
+ systems.url = "github:nix-systems/default";
+ treefmt-nix.url = "github:numtide/treefmt-nix";
+ };
+
+ outputs = inputs:
+ inputs.flake-parts.lib.mkFlake { inherit inputs; } {
+ systems = import inputs.systems;
+ imports = [
+ inputs.treefmt-nix.flakeModule
+ ];
+ perSystem = { config, self', pkgs, lib, system, ... }:
+ let
+ nonRustDeps = [
+ pkgs.libiconv
+ ];
+ in
+ {
+ # Rust dev environment
+ devShells.default = pkgs.mkShell {
+ inputsFrom = [
+ config.treefmt.build.devShell
+ ];
+ shellHook = ''
+ # For rust-analyzer 'hover' tooltips to work.
+ export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc}
+
+ echo
+ echo "🍎🍎 Run 'just <recipe>' to get started"
+ just
+ '';
+ buildInputs = nonRustDeps;
+ nativeBuildInputs = with pkgs; [
+ just
+ rustc
+ cargo
+ cargo-watch
+ rust-analyzer
+ ];
+ };
+
+ # Add your auto-formatters here.
+ # cf. https://numtide.github.io/treefmt/
+ treefmt.config = {
+ projectRootFile = "flake.nix";
+ programs = {
+ nixpkgs-fmt.enable = true;
+ rustfmt.enable = true;
+ };
+ };
+ };
+ };
+}