dotfiles.nix/templates/rust/flake.nix

52 lines
1.8 KiB
Nix

{
description = "FILL-ME-IN";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
crane.url = "github:ipetkov/crane";
crane.inputs.nixpkgs.follows = "nixpkgs";
pre-commit.url = "github:cachix/pre-commit-hooks.nix";
pre-commit.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs@{ self, flake-parts, crane, pre-commit, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ pre-commit.flakeModule ];
systems =
[ "aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux" ];
perSystem = { config, pkgs, system, ... }:
let
crane-lib = crane.lib.${system};
package = crane-lib.buildPackage {
src = crane-lib.cleanCargoSource ./.;
nativeBuildInputs =
pkgs.lib.optionals pkgs.stdenv.isDarwin [ pkgs.libiconv ];
};
in {
pre-commit.settings.hooks = {
rustfmt.enable = true;
clippy.enable = true;
cargo-check.enable = true;
};
checks = { inherit package; };
packages.default = package;
devShells.default = pkgs.mkShell {
shellHook = ''
${config.pre-commit.installationScript}
echo "welcome to your rust project ()" 1>&2
'';
inputsFrom = builtins.attrValues self.checks;
RUST_SRC_PATH =
"${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
nativeBuildInputs =
builtins.attrValues { inherit (pkgs) cargo rustc; };
buildInputs = builtins.attrValues {
inherit (pkgs) rust-analyzer rustfmt clippy;
};
};
};
};
}