rust-nix-template/flake.nix

69 lines
2 KiB
Nix
Raw Normal View History

2021-04-07 00:17:50 +02:00
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
2023-06-26 18:32:36 +02:00
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";
# Dev tools
treefmt-nix.url = "github:numtide/treefmt-nix";
2021-04-07 00:17:50 +02:00
};
2023-06-26 18:32:36 +02:00
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
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
nonRustDeps = [
pkgs.libiconv
2023-06-26 18:32:36 +02:00
];
rust-toolchain = pkgs.symlinkJoin {
name = "rust-toolchain";
paths = [ pkgs.rustc pkgs.cargo pkgs.cargo-watch pkgs.rust-analyzer pkgs.rustPlatform.rustcSrc ];
};
in
{
# Rust package
2023-07-23 16:11:14 +02:00
packages.default = pkgs.rustPlatform.buildRustPackage {
inherit (cargoToml.package) name version;
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
};
2023-06-26 18:32:36 +02:00
# 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}
2023-10-25 20:27:38 +02:00
echo
echo "🍎🍎 Run 'just <recipe>' to get started"
just
'';
buildInputs = nonRustDeps;
nativeBuildInputs = with pkgs; [
2023-07-23 16:10:10 +02:00
just
rust-toolchain
];
RUST_BACKTRACE = 1;
2023-06-26 18:32:36 +02:00
};
# Add your auto-formatters here.
# cf. https://numtide.github.io/treefmt/
treefmt.config = {
projectRootFile = "flake.nix";
programs = {
nixpkgs-fmt.enable = true;
rustfmt.enable = true;
};
2023-06-26 18:32:36 +02:00
};
};
};
2021-04-07 00:17:50 +02:00
}