patagia-control/flake.nix

180 lines
5 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
rustVersion = "1.81.0"; # Skipping 1.82 because of https://github.com/rust-lang/rust/issues/132064
overlays = [
(import rust-overlay)
(final: prev: {
nix-filter = nix-filter.lib;
rust-toolchain = pkgs.rust-bin.stable.${rustVersion}.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;
};
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";
};
commonArgs = {
inherit src stdenv nativeBuildInputs;
strictDeps = true;
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
individualCrateArgs = commonArgs // {
inherit cargoArtifacts;
inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
doCheck = false; # We use cargo-nextest for all tests
};
fileSetForCrate =
crate:
pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [
./Cargo.toml
./Cargo.lock
(craneLib.fileset.commonCargoSources ./agent)
(craneLib.fileset.commonCargoSources ./controller)
(craneLib.fileset.commonCargoSources crate)
];
};
patagia-agent = craneLib.buildPackage (
individualCrateArgs
// {
pname = "patagia-agent";
cargoExtraArgs = "-p patagia-agent";
src = fileSetForCrate ./agent;
}
);
patagia-controller = craneLib.buildPackage (
individualCrateArgs
// {
pname = "patagia-controller";
cargoExtraArgs = "-p patagia-controller";
src = fileSetForCrate ./controller;
}
);
2024-10-20 19:29:28 +02:00
in
{
2024-11-23 19:57:17 +01:00
# `nix build`
packages = {
inherit patagia-agent patagia-controller;
};
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
inherit patagia-agent patagia-controller;
2024-10-20 19:29:28 +02:00
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; });
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-hakari
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 development environment! "
2024-10-20 19:29:28 +02:00
echo "Run 'just' to see available commands."
echo
'';
};
}
);
}