generated from Patagia/template-nix
Add progenitor client #3
12 changed files with 1032 additions and 55 deletions
958
Cargo.lock
generated
958
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -36,9 +36,11 @@ opentelemetry-otlp = { version = "0.27.0", features = ["grpc-tonic", "trace"] }
|
|||
opentelemetry_sdk = { version = "0.27.1", features = ["metrics", "rt-tokio"] }
|
||||
opentelemetry-semantic-conventions = "0.27.0"
|
||||
opentelemetry-stdout = "0.27.0"
|
||||
progenitor = "0.8.0"
|
||||
reqwest = { version = "0.12.9", features = ["json", "stream", "rustls-tls"] }
|
||||
schemars = "0.8.21"
|
||||
semver = "1.0.23"
|
||||
serde = "1.0.215"
|
||||
serde = { version = "1.0.215", features = ["derive"] }
|
||||
slog = "2.7.0"
|
||||
slog-async = "2.8.0"
|
||||
tokio = { version = "1.41.1", features = ["full"] }
|
||||
|
@ -53,3 +55,4 @@ tracing-subscriber = { version = "0.3.18", default-features = false, features =
|
|||
"env-filter",
|
||||
"fmt",
|
||||
] }
|
||||
uuid = { version = "1", features = [ "serde", "v4" ] }
|
||||
|
|
|
@ -7,10 +7,14 @@ license = "MPL-2.0"
|
|||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
clap.workspace = true
|
||||
progenitor.workspace = true
|
||||
reqwest.workspace = true
|
||||
schemars.workspace = true
|
||||
serde.workspace = true
|
||||
tokio.workspace = true
|
||||
tracing.workspace = true
|
||||
tracing-chrome.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
tracing.workspace = true
|
||||
|
||||
[[bin]]
|
||||
name = "patagia-agent"
|
||||
|
|
|
@ -3,6 +3,8 @@ use clap::Parser;
|
|||
use tokio::time::{sleep, Duration};
|
||||
use tracing_subscriber::prelude::*;
|
||||
|
||||
mod patagia_api;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Cli {}
|
||||
|
@ -19,6 +21,10 @@ async fn main() -> Result<()> {
|
|||
|
||||
tracing::info!("Patagia Agent");
|
||||
|
||||
let client = patagia_api::Client::new("http://localhost:9474");
|
||||
let result = client.version().await?;
|
||||
tracing::info!("Result: {:?}", result);
|
||||
|
||||
sleep(Duration::from_secs(3)).await;
|
||||
Ok(())
|
||||
}
|
||||
|
|
3
agent/src/patagia_api.rs
Normal file
3
agent/src/patagia_api.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
use progenitor::generate_api;
|
||||
|
||||
generate_api!(spec = "../api.json", derives = [schemars::JsonSchema]);
|
2
api.json
2
api.json
|
@ -8,7 +8,7 @@
|
|||
"/version": {
|
||||
"get": {
|
||||
"summary": "Fetch version info.",
|
||||
"operationId": "api_version",
|
||||
"operationId": "version",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "successful operation",
|
||||
|
|
|
@ -28,7 +28,7 @@ tracing-opentelemetry.workspace = true
|
|||
tracing-slog.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
tracing.workspace = true
|
||||
|
||||
[[bin]]
|
||||
name = "patagia-controller"
|
||||
doc = false
|
||||
#
|
||||
# [[bin]]
|
||||
# name = "patagia-controller"
|
||||
# doc = false
|
||||
|
|
|
@ -10,6 +10,6 @@ type ControllerApiDescription = ApiDescription<Arc<ControllerContext>>;
|
|||
|
||||
pub fn api() -> Result<ControllerApiDescription> {
|
||||
let mut api = ControllerApiDescription::new();
|
||||
api.register(version::api_version)?;
|
||||
api.register(version::version)?;
|
||||
Ok(api)
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ struct VersionInfo {
|
|||
),
|
||||
err(Debug),
|
||||
)]
|
||||
pub async fn api_version(
|
||||
pub(crate) async fn version(
|
||||
rqctx: RequestContext<Arc<ControllerContext>>,
|
||||
) -> Result<HttpResponseOk<VersionInfo>, HttpError> {
|
||||
let ver = VersionInfo {
|
||||
|
|
30
flake.lock
30
flake.lock
|
@ -3,11 +3,11 @@
|
|||
"advisory-db": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1731808107,
|
||||
"narHash": "sha256-HSx5EDsO07KULW4bNPVeGVAfpQqzwwS005vqISdOzNg=",
|
||||
"lastModified": 1733749954,
|
||||
"narHash": "sha256-2Ug80Uf/oUujxgh02Iy5vTG0V+Ab9+YUHuRLRY0ayiY=",
|
||||
"owner": "rustsec",
|
||||
"repo": "advisory-db",
|
||||
"rev": "8e353a172f1baf11c0c917cfc9ae3c5eff8b9d06",
|
||||
"rev": "ec9ce28714bb38d77a2223e7266df705500a7f11",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -18,11 +18,11 @@
|
|||
},
|
||||
"crane": {
|
||||
"locked": {
|
||||
"lastModified": 1731974733,
|
||||
"narHash": "sha256-enYSSZVVl15FI5p+0Y5/Ckf5DZAvXe6fBrHxyhA/njc=",
|
||||
"lastModified": 1733688869,
|
||||
"narHash": "sha256-KrhxxFj1CjESDrL5+u/zsVH0K+Ik9tvoac/oFPoxSB8=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "3cb338ce81076ce5e461cf77f7824476addb0e1c",
|
||||
"rev": "604637106e420ad99907cae401e13ab6b452e7d9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -98,11 +98,11 @@
|
|||
},
|
||||
"nixpkgs_3": {
|
||||
"locked": {
|
||||
"lastModified": 1731890469,
|
||||
"narHash": "sha256-D1FNZ70NmQEwNxpSSdTXCSklBH1z2isPR84J6DQrJGs=",
|
||||
"lastModified": 1733097829,
|
||||
"narHash": "sha256-9hbb1rqGelllb4kVUCZ307G2k3/UhmA8PPGBoyuWaSw=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "5083ec887760adfe12af64830a66807423a859a7",
|
||||
"rev": "2c15aa59df0017ca140d9ba302412298ab4bf22a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -128,11 +128,11 @@
|
|||
"nixpkgs": "nixpkgs_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1732328983,
|
||||
"narHash": "sha256-RHt12f/slrzDpSL7SSkydh8wUE4Nr4r23HlpWywed9E=",
|
||||
"lastModified": 1734230139,
|
||||
"narHash": "sha256-zsp0Mz8VgyIAnU8UhP/YT1g+zlsl+NIJTBMAbY+RifQ=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "ed8aa5b64f7d36d9338eb1d0a3bb60cf52069a72",
|
||||
"rev": "150fbc8aa2bc501041810bbc1dbfe73694a861be",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -161,11 +161,11 @@
|
|||
"nixpkgs": "nixpkgs_3"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1732292307,
|
||||
"narHash": "sha256-5WSng844vXt8uytT5djmqBCkopyle6ciFgteuA9bJpw=",
|
||||
"lastModified": 1733761991,
|
||||
"narHash": "sha256-s4DalCDepD22jtKL5Nw6f4LP5UwoMcPzPZgHWjAfqbQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "treefmt-nix",
|
||||
"rev": "705df92694af7093dfbb27109ce16d828a79155f",
|
||||
"rev": "0ce9d149d99bc383d1f2d85f31f6ebd146e46085",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
57
flake.nix
57
flake.nix
|
@ -26,7 +26,7 @@
|
|||
flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
rustVersion = "1.81.0"; # Skipping 1.82 because of https://github.com/rust-lang/rust/issues/132064
|
||||
rustVersion = "1.83.0";
|
||||
|
||||
overlays = [
|
||||
(import rust-overlay)
|
||||
|
@ -49,29 +49,24 @@
|
|||
nativeBuildInputs = with pkgs; [
|
||||
clang_18
|
||||
mold
|
||||
pkg-config
|
||||
];
|
||||
|
||||
sourceAndFixtures = path: type: (craneLib.filterCargoSources path type);
|
||||
jsonFilter = path: _type: builtins.match ".*json$" path != null;
|
||||
sourceAndFixtures = path: type:
|
||||
(jsonFilter 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";
|
||||
buildInputs = with pkgs; [
|
||||
openssl
|
||||
];
|
||||
};
|
||||
|
||||
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
||||
|
@ -123,6 +118,18 @@
|
|||
src = fileSetForCrate ./xtask;
|
||||
}
|
||||
);
|
||||
|
||||
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";
|
||||
};
|
||||
|
||||
in
|
||||
{
|
||||
# `nix build`
|
||||
|
@ -142,7 +149,7 @@
|
|||
}
|
||||
);
|
||||
|
||||
fmt = craneLib.cargoFmt (commonArgs // { inherit src; });
|
||||
# fmt = craneLib.cargoFmt (commonArgs // { inherit src; });
|
||||
|
||||
audit = craneLib.cargoAudit (commonArgs // { inherit src advisory-db; });
|
||||
|
||||
|
@ -156,11 +163,17 @@
|
|||
);
|
||||
|
||||
openapi =
|
||||
pkgs.runCommand "openapi" (commonArgs // {
|
||||
src = fileSetForCrate ./xtask;
|
||||
}) ''
|
||||
${self.packages.${system}.xtask}/bin/xtask open-api | ${pkgs.diffutils}/bin/diff -u $src/api.json - | tee $out
|
||||
'';
|
||||
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
|
||||
'';
|
||||
};
|
||||
|
||||
# For `nix fmt`
|
||||
|
@ -178,14 +191,16 @@
|
|||
cargo-nextest
|
||||
cargo-watch
|
||||
hyperfine
|
||||
openssl
|
||||
just
|
||||
rust-dev-toolchain
|
||||
watchexec
|
||||
];
|
||||
RUST_BACKTRACE = 1;
|
||||
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc; # Required for rust-analyzer
|
||||
shellHook = ''
|
||||
export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc} # Required for rust-analyzer
|
||||
echo
|
||||
echo "✨ Welcome to the Patagia development environment! ✨"
|
||||
echo "✨🛠️ Welcome to the Patagia development environment 🛠️✨"
|
||||
echo "Run 'just' to see available commands."
|
||||
echo
|
||||
'';
|
||||
|
|
8
justfile
8
justfile
|
@ -12,6 +12,14 @@ run-controller $RUST_LOG="debug,h2=info,hyper_util=info,tower=info":
|
|||
dev-controller:
|
||||
watchexec --clear --restart --stop-signal INT --debounce 300ms -- just run-controller
|
||||
|
||||
# Run agent
|
||||
run-agent $RUST_LOG="debug,h2=info,hyper_util=info,tower=info":
|
||||
cargo run --package patagia-agent
|
||||
|
||||
# Run agent local development
|
||||
dev-agent:
|
||||
watchexec --clear --restart --stop-signal INT --debounce 300ms -- just run-agent
|
||||
|
||||
# Lint all source code
|
||||
lint:
|
||||
cargo clippy
|
||||
|
|
Loading…
Reference in a new issue
A comment after the fact...