patagia-control/flake.nix

137 lines
3.7 KiB
Nix
Raw Normal View History

2024-10-20 19:29:28 +02:00
{
inputs = {
2024-11-23 19:57:17 +01:00
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
crane.url = "github:ipetkov/crane";
2024-10-20 19:29:28 +02:00
flake-utils.url = "github:numtide/flake-utils";
2024-11-23 19:57:17 +01:00
nix-filter.url = "github:numtide/nix-filter";
2024-10-20 19:29:28 +02:00
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
2024-11-23 19:57:17 +01:00
rust-overlay.url = "github:oxalica/rust-overlay";
treefmt-nix.url = "github:numtide/treefmt-nix";
2024-10-20 19:29:28 +02:00
};
outputs =
{
self,
2024-11-23 19:57:17 +01:00
advisory-db,
crane,
2024-10-20 19:29:28 +02:00
flake-utils,
2024-11-23 19:57:17 +01:00
nix-filter,
2024-10-20 19:29:28 +02:00
nixpkgs,
2024-11-23 19:57:17 +01:00
rust-overlay,
treefmt-nix,
2024-10-20 19:29:28 +02:00
}:
flake-utils.lib.eachDefaultSystem (
system:
let
2024-11-23 19:57:17 +01:00
overlays = [
(import rust-overlay)
(final: prev: {
nix-filter = nix-filter.lib;
rust-toolchain = pkgs.rust-bin.stable.latest.default;
rust-dev-toolchain = pkgs.rust-toolchain.override {
extensions = [
"rust-analyzer"
"rust-src"
];
};
})
];
pkgs = import nixpkgs { inherit overlays system; };
craneLib = (crane.mkLib pkgs).overrideToolchain pkgs.rust-toolchain;
stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv;
nativeBuildInputs = with pkgs; [
clang_18
mold
];
sourceAndFixtures = path: type: (craneLib.filterCargoSources path type);
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter = sourceAndFixtures;
};
commonArgs = {
inherit src stdenv nativeBuildInputs;
strictDeps = true;
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
treefmtEval = treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";
programs = {
nixfmt.enable = true;
nixfmt.package = pkgs.nixfmt-rfc-style;
shfmt.enable = true;
rustfmt.enable = true;
};
settings.formatter.rustfmt.command = pkgs.lib.mkForce "${pkgs.rust-toolchain}/bin/rustfmt";
};
my-project = craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; });
2024-10-20 19:29:28 +02:00
in
2024-11-23 19:57:17 +01:00
rec {
# `nix build`
packages.default = my-project;
2024-10-20 19:29:28 +02:00
2024-11-23 19:57:17 +01:00
# Tests
2024-10-20 19:29:28 +02:00
checks = {
2024-11-23 19:57:17 +01:00
clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
2024-10-20 19:29:28 +02:00
2024-11-23 19:57:17 +01:00
fmt = craneLib.cargoFmt (commonArgs // { inherit src; });
2024-10-20 19:29:28 +02:00
2024-11-23 19:57:17 +01:00
audit = craneLib.cargoAudit (commonArgs // { inherit src advisory-db; });
nextest = craneLib.cargoNextest (
commonArgs
// {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
}
);
2024-10-20 19:29:28 +02:00
};
2024-11-23 19:57:17 +01:00
# For `nix fmt`
formatter = treefmtEval.config.build.wrapper;
# `nix develop`
2024-10-20 19:29:28 +02:00
devShells.default = pkgs.mkShell {
2024-11-23 19:57:17 +01:00
inherit nativeBuildInputs;
2024-10-20 19:29:28 +02:00
buildInputs = with pkgs; [
2024-11-23 19:57:17 +01:00
bacon
cargo-edit
cargo-features-manager
cargo-machete
cargo-nextest
cargo-watch
hyperfine
2024-10-20 19:29:28 +02:00
just
2024-11-23 19:57:17 +01:00
rust-dev-toolchain
2024-10-20 19:29:28 +02:00
watchexec
];
shellHook = ''
2024-11-23 19:57:17 +01:00
export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc} # Required for rust-analyzer
2024-10-20 19:29:28 +02:00
echo
2024-11-23 19:57:17 +01:00
echo " Welcome to the Patagia Controller development environment! "
2024-10-20 19:29:28 +02:00
echo "Run 'just' to see available commands."
echo
'';
};
}
);
}