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-12-15 10:17:38 +01:00
|
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
|
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-12-15 11:53:40 +01:00
|
|
|
|
rustVersion = "1.83.0";
|
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.${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
|
2024-12-14 22:47:40 +01:00
|
|
|
|
pkg-config
|
2024-11-23 19:57:17 +01:00
|
|
|
|
];
|
|
|
|
|
|
2024-12-14 22:47:40 +01:00
|
|
|
|
jsonFilter = path: _type: builtins.match ".*json$" path != null;
|
|
|
|
|
sourceAndFixtures = path: type:
|
|
|
|
|
(jsonFilter path type) || (craneLib.filterCargoSources path type);
|
2024-11-23 19:57:17 +01:00
|
|
|
|
src = pkgs.lib.cleanSourceWith {
|
|
|
|
|
src = ./.;
|
|
|
|
|
filter = sourceAndFixtures;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
commonArgs = {
|
|
|
|
|
inherit src stdenv nativeBuildInputs;
|
|
|
|
|
strictDeps = true;
|
|
|
|
|
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
|
2024-12-14 22:47:40 +01:00
|
|
|
|
buildInputs = with pkgs; [
|
|
|
|
|
openssl
|
|
|
|
|
];
|
2024-11-23 19:57:17 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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 [
|
2024-12-11 21:12:24 +01:00
|
|
|
|
./api.json
|
2024-11-23 19:57:17 +01:00
|
|
|
|
./Cargo.toml
|
|
|
|
|
./Cargo.lock
|
|
|
|
|
(craneLib.fileset.commonCargoSources ./agent)
|
|
|
|
|
(craneLib.fileset.commonCargoSources ./controller)
|
2024-12-11 21:12:24 +01:00
|
|
|
|
(craneLib.fileset.commonCargoSources ./xtask)
|
2024-11-23 19:57:17 +01:00
|
|
|
|
(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-12-11 21:12:24 +01:00
|
|
|
|
xtask = craneLib.buildPackage (
|
|
|
|
|
individualCrateArgs
|
|
|
|
|
// {
|
|
|
|
|
pname = "xtask";
|
|
|
|
|
cargoExtraArgs = "-p xtask";
|
|
|
|
|
src = fileSetForCrate ./xtask;
|
|
|
|
|
}
|
|
|
|
|
);
|
2024-12-14 22:47:40 +01:00
|
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-20 19:29:28 +02:00
|
|
|
|
in
|
|
|
|
|
{
|
2024-11-23 19:57:17 +01:00
|
|
|
|
# `nix build`
|
|
|
|
|
packages = {
|
2024-12-11 21:12:24 +01:00
|
|
|
|
inherit patagia-agent patagia-controller xtask;
|
2024-11-23 19:57:17 +01:00
|
|
|
|
};
|
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-12-11 21:12:24 +01:00
|
|
|
|
inherit patagia-agent patagia-controller xtask;
|
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-12-14 22:47:40 +01:00
|
|
|
|
# fmt = craneLib.cargoFmt (commonArgs // { inherit src; });
|
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-12-11 21:12:24 +01:00
|
|
|
|
|
|
|
|
|
openapi =
|
2024-12-14 22:47:40 +01:00
|
|
|
|
pkgs.runCommand "openapi"
|
|
|
|
|
(
|
|
|
|
|
commonArgs
|
|
|
|
|
// {
|
|
|
|
|
inherit cargoArtifacts;
|
|
|
|
|
src = fileSetForCrate ./xtask;
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
''
|
|
|
|
|
${self.packages.${system}.xtask}/bin/xtask open-api | ${pkgs.diffutils}/bin/diff -u $src/api.json - | tee $out
|
|
|
|
|
'';
|
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-12-14 22:47:40 +01:00
|
|
|
|
openssl
|
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
|
|
|
|
|
];
|
2024-12-14 22:47:40 +01:00
|
|
|
|
RUST_BACKTRACE = 1;
|
|
|
|
|
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc; # Required for rust-analyzer
|
2024-10-20 19:29:28 +02:00
|
|
|
|
shellHook = ''
|
|
|
|
|
echo
|
2024-12-14 22:47:40 +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
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|