rust-nix-template/flake.nix

63 lines
1.7 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
];
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}
'';
buildInputs = nonRustDeps;
nativeBuildInputs = with pkgs; [
2023-07-23 16:10:10 +02:00
just
rustc
cargo
cargo-watch
rust-analyzer
];
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
}