diff --git a/.github/workflows/autofix.yml b/.github/workflows/autofix.yml index e69c473..591937a 100644 --- a/.github/workflows/autofix.yml +++ b/.github/workflows/autofix.yml @@ -41,7 +41,7 @@ jobs: ~/.cargo/git/db/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: setup sqlx - run: nix develop -L -v -c sqlx database setup --source ./wire/lib/src/cache/migrations/ + run: nix develop -L -v -c sqlx database setup --source ./crates/core/src/cache/migrations/ - name: autofix sqlx run: nix develop -L -v -c cargo sqlx prepare --workspace - name: clippy --fix diff --git a/Cargo.lock b/Cargo.lock index 3a8b31d..b250e99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1119,21 +1119,6 @@ dependencies = [ "libc", ] -[[package]] -name = "key_agent" -version = "1.0.0" -dependencies = [ - "anyhow", - "base64", - "futures-util", - "nix 0.30.1", - "prost", - "prost-build", - "sha2", - "tokio", - "tokio-util", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -1143,45 +1128,6 @@ dependencies = [ "spin", ] -[[package]] -name = "lib" -version = "1.0.0" -dependencies = [ - "aho-corasick", - "anyhow", - "base64", - "derive_more", - "enum_dispatch", - "futures", - "gethostname", - "gjson", - "im", - "itertools", - "key_agent", - "miette", - "nix 0.30.1", - "nix-compat", - "num_enum", - "owo-colors", - "portable-pty", - "proc-macro2", - "prost", - "rand 0.9.2", - "serde", - "serde_json", - "sha2", - "sqlx", - "strip-ansi-escapes", - "syn 2.0.111", - "tempdir", - "termion", - "thiserror 2.0.17", - "tokio", - "tokio-util", - "tracing", - "zstd", -] - [[package]] name = "libc" version = "0.2.175" @@ -3223,7 +3169,6 @@ dependencies = [ "futures", "im", "itertools", - "lib", "miette", "nix-compat", "owo-colors", @@ -3236,6 +3181,61 @@ dependencies = [ "tracing", "tracing-log", "tracing-subscriber", + "wire-core", +] + +[[package]] +name = "wire-core" +version = "1.0.0" +dependencies = [ + "aho-corasick", + "anyhow", + "base64", + "derive_more", + "enum_dispatch", + "futures", + "gethostname", + "gjson", + "im", + "itertools", + "miette", + "nix 0.30.1", + "nix-compat", + "num_enum", + "owo-colors", + "portable-pty", + "proc-macro2", + "prost", + "rand 0.9.2", + "serde", + "serde_json", + "sha2", + "sqlx", + "strip-ansi-escapes", + "syn 2.0.111", + "tempdir", + "termion", + "thiserror 2.0.17", + "tokio", + "tokio-util", + "tracing", + "wire-key-agent", + "zstd", +] + +[[package]] +name = "wire-key-agent" +version = "1.0.0" +dependencies = [ + "anyhow", + "base64", + "futures-util", + "nix 0.30.1", + "prost", + "prost-build", + "sha2", + "tokio", + "tokio-util", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 4b28757..bf490d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["wire/key_agent", "wire/lib", "wire/cli"] +members = ["crates/key_agent", "crates/core", "crates/cli"] resolver = "2" package.edition = "2024" package.version = "1.0.0" diff --git a/README.md b/README.md index 889c9d8..303c38c 100644 --- a/README.md +++ b/README.md @@ -6,27 +6,6 @@ wire is a tool to deploy nixos systems. its usage is inspired by colmena however Read the [The Tutorial](https://wire.althaea.zone/tutorial/overview.html), [Guides](https://wire.althaea.zone/guides/installation.html), or continue reading this readme for development information. -## Tree Layout - -``` -wire -├── wire -│ ├── lib -│ │ └── Rust library containing business logic, consumed by `wire` -│ ├── cli -│ │ └── Rust binary, using `lib` -│ └── key_agent -│ └── Rust binary ran on a target node. receives key file bytes and metadata w/ protobuf over SSH stdin -├── doc -│ └── a [vitepress](https://vitepress.dev/) site -├── runtime -│ └── Nix files used during runtime to evaluate nodes -├── bench -│ └── A little tool to benchmark wire against a large hive -└──tests - └── Directories used during cargo & NixOS VM testing -``` - ## Development Please use `nix develop` for access to the development environment and to ensure diff --git a/wire/cli/Cargo.toml b/crates/cli/Cargo.toml similarity index 96% rename from wire/cli/Cargo.toml rename to crates/cli/Cargo.toml index f36e185..f150b81 100644 --- a/wire/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -17,7 +17,7 @@ tokio = { workspace = true } tracing = { workspace = true } tracing-log = { workspace = true } tracing-subscriber = { workspace = true } -lib = { path = "../lib" } +wire-core = { path = "../core" } serde_json = { workspace = true } miette = { workspace = true } thiserror = { workspace = true } diff --git a/wire/cli/default.nix b/crates/cli/default.nix similarity index 97% rename from wire/cli/default.nix rename to crates/cli/default.nix index 5b123f2..317bdd8 100644 --- a/wire/cli/default.nix +++ b/crates/cli/default.nix @@ -30,7 +30,7 @@ preBuild = '' export DATABASE_URL=sqlite:./db.sqlite3 sqlx database create - sqlx migrate run --source ./wire/lib/src/cache/migrations/ + sqlx migrate run --source ./crates/core/src/cache/migrations/ ''; postInstall = '' installShellCompletion --cmd wire \ diff --git a/wire/cli/src/apply.rs b/crates/cli/src/apply.rs similarity index 95% rename from wire/cli/src/apply.rs rename to crates/cli/src/apply.rs index 7f79935..7fd1e14 100644 --- a/wire/cli/src/apply.rs +++ b/crates/cli/src/apply.rs @@ -3,10 +3,6 @@ use futures::{FutureExt, StreamExt}; use itertools::{Either, Itertools}; -use lib::hive::node::{Context, GoalExecutor, Name, StepState, should_apply_locally}; -use lib::hive::{Hive, HiveLocation}; -use lib::status::STATUS; -use lib::{SubCommandModifiers, errors::HiveLibError}; use miette::{Diagnostic, IntoDiagnostic, Result}; use std::collections::HashSet; use std::io::{Read, stderr}; @@ -14,6 +10,10 @@ use std::sync::Arc; use std::sync::atomic::AtomicBool; use thiserror::Error; use tracing::{Span, error, info}; +use wire_core::hive::node::{Context, GoalExecutor, Name, StepState, should_apply_locally}; +use wire_core::hive::{Hive, HiveLocation}; +use wire_core::status::STATUS; +use wire_core::{SubCommandModifiers, errors::HiveLibError}; use crate::cli::{ApplyArgs, ApplyTarget}; diff --git a/wire/cli/src/cli.rs b/crates/cli/src/cli.rs similarity index 95% rename from wire/cli/src/cli.rs rename to crates/cli/src/cli.rs index 356464a..1d62394 100644 --- a/wire/cli/src/cli.rs +++ b/crates/cli/src/cli.rs @@ -8,11 +8,11 @@ use clap_complete::CompletionCandidate; use clap_complete::engine::ArgValueCompleter; use clap_num::number_range; use clap_verbosity_flag::InfoLevel; -use lib::SubCommandModifiers; -use lib::commands::common::get_hive_node_names; -use lib::hive::node::{Goal as HiveGoal, HandleUnreachable, Name, SwitchToConfigurationGoal}; -use lib::hive::{Hive, get_hive_location}; use tokio::runtime::Handle; +use wire_core::SubCommandModifiers; +use wire_core::commands::common::get_hive_node_names; +use wire_core::hive::node::{Goal as HiveGoal, HandleUnreachable, Name, SwitchToConfigurationGoal}; +use wire_core::hive::{Hive, get_hive_location}; use std::io::IsTerminal; use std::{ @@ -252,8 +252,10 @@ impl ToSubCommandModifiers for Cli { show_trace: self.show_trace, non_interactive: self.non_interactive, ssh_accept_host: match &self.command { - Commands::Apply(args) if args.ssh_accept_host => lib::StrictHostKeyChecking::No, - _ => lib::StrictHostKeyChecking::default(), + Commands::Apply(args) if args.ssh_accept_host => { + wire_core::StrictHostKeyChecking::No + } + _ => wire_core::StrictHostKeyChecking::default(), }, } } diff --git a/wire/cli/src/main.rs b/crates/cli/src/main.rs similarity index 95% rename from wire/cli/src/main.rs rename to crates/cli/src/main.rs index 4d70035..156c499 100644 --- a/wire/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -15,16 +15,16 @@ use crate::tracing_setup::setup_logging; use clap::CommandFactory; use clap::Parser; use clap_complete::CompleteEnv; -use lib::cache::InspectionCache; -use lib::commands::common::get_hive_node_names; -use lib::hive::Hive; -use lib::hive::get_hive_location; use miette::IntoDiagnostic; use miette::Result; use signal_hook::consts::SIGINT; use signal_hook_tokio::Signals; use tracing::error; use tracing::warn; +use wire_core::cache::InspectionCache; +use wire_core::commands::common::get_hive_node_names; +use wire_core::hive::Hive; +use wire_core::hive::get_hive_location; #[macro_use] extern crate enum_display_derive; diff --git a/wire/cli/src/sigint.rs b/crates/cli/src/sigint.rs similarity index 100% rename from wire/cli/src/sigint.rs rename to crates/cli/src/sigint.rs diff --git a/wire/cli/src/tracing_setup.rs b/crates/cli/src/tracing_setup.rs similarity index 99% rename from wire/cli/src/tracing_setup.rs rename to crates/cli/src/tracing_setup.rs index 30a18ef..8e5ac2d 100644 --- a/wire/cli/src/tracing_setup.rs +++ b/crates/cli/src/tracing_setup.rs @@ -8,7 +8,6 @@ use std::{ }; use clap_verbosity_flag::{LogLevel, Verbosity}; -use lib::{STDIN_CLOBBER_LOCK, status::STATUS}; use owo_colors::{OwoColorize, Stream, Style}; use tracing::{Level, Subscriber}; use tracing_log::AsTrace; @@ -23,6 +22,7 @@ use tracing_subscriber::{ registry::LookupSpan, util::SubscriberInitExt, }; +use wire_core::{STDIN_CLOBBER_LOCK, status::STATUS}; /// The non-clobbering writer ensures that log lines are held while interactive /// prompts are shown to the user. If logs where shown, they would "clobber" the diff --git a/wire/lib/Cargo.toml b/crates/core/Cargo.toml similarity index 94% rename from wire/lib/Cargo.toml rename to crates/core/Cargo.toml index 1c4c15e..648312a 100644 --- a/wire/lib/Cargo.toml +++ b/crates/core/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "lib" +name = "wire-core" version.workspace = true edition.workspace = true @@ -17,7 +17,7 @@ tracing = { workspace = true } im = { workspace = true } thiserror = "2.0.17" derive_more = { version = "2.0.1", features = ["display"] } -key_agent = { path = "../key_agent" } +wire-key-agent = { path = "../key_agent" } futures = "0.3.31" prost = { workspace = true } gethostname = "1.1.0" diff --git a/wire/lib/build.rs b/crates/core/build.rs similarity index 100% rename from wire/lib/build.rs rename to crates/core/build.rs diff --git a/wire/lib/src/cache/migrations/20251124234730_init.sql b/crates/core/src/cache/migrations/20251124234730_init.sql similarity index 100% rename from wire/lib/src/cache/migrations/20251124234730_init.sql rename to crates/core/src/cache/migrations/20251124234730_init.sql diff --git a/wire/lib/src/cache/migrations/20251126222409_blobs.sql b/crates/core/src/cache/migrations/20251126222409_blobs.sql similarity index 100% rename from wire/lib/src/cache/migrations/20251126222409_blobs.sql rename to crates/core/src/cache/migrations/20251126222409_blobs.sql diff --git a/wire/lib/src/cache/mod.rs b/crates/core/src/cache/mod.rs similarity index 100% rename from wire/lib/src/cache/mod.rs rename to crates/core/src/cache/mod.rs diff --git a/wire/lib/src/commands/common.rs b/crates/core/src/commands/common.rs similarity index 100% rename from wire/lib/src/commands/common.rs rename to crates/core/src/commands/common.rs diff --git a/wire/lib/src/commands/mod.rs b/crates/core/src/commands/mod.rs similarity index 100% rename from wire/lib/src/commands/mod.rs rename to crates/core/src/commands/mod.rs diff --git a/wire/lib/src/commands/noninteractive.rs b/crates/core/src/commands/noninteractive.rs similarity index 100% rename from wire/lib/src/commands/noninteractive.rs rename to crates/core/src/commands/noninteractive.rs diff --git a/wire/lib/src/commands/pty/input.rs b/crates/core/src/commands/pty/input.rs similarity index 100% rename from wire/lib/src/commands/pty/input.rs rename to crates/core/src/commands/pty/input.rs diff --git a/wire/lib/src/commands/pty/logbuffer.rs b/crates/core/src/commands/pty/logbuffer.rs similarity index 100% rename from wire/lib/src/commands/pty/logbuffer.rs rename to crates/core/src/commands/pty/logbuffer.rs diff --git a/wire/lib/src/commands/pty/mod.rs b/crates/core/src/commands/pty/mod.rs similarity index 100% rename from wire/lib/src/commands/pty/mod.rs rename to crates/core/src/commands/pty/mod.rs diff --git a/wire/lib/src/commands/pty/output.rs b/crates/core/src/commands/pty/output.rs similarity index 100% rename from wire/lib/src/commands/pty/output.rs rename to crates/core/src/commands/pty/output.rs diff --git a/wire/lib/src/errors.rs b/crates/core/src/errors.rs similarity index 100% rename from wire/lib/src/errors.rs rename to crates/core/src/errors.rs diff --git a/wire/lib/src/hive/mod.rs b/crates/core/src/hive/mod.rs similarity index 100% rename from wire/lib/src/hive/mod.rs rename to crates/core/src/hive/mod.rs diff --git a/wire/lib/src/hive/node.rs b/crates/core/src/hive/node.rs similarity index 100% rename from wire/lib/src/hive/node.rs rename to crates/core/src/hive/node.rs diff --git a/wire/lib/src/hive/steps/activate.rs b/crates/core/src/hive/steps/activate.rs similarity index 100% rename from wire/lib/src/hive/steps/activate.rs rename to crates/core/src/hive/steps/activate.rs diff --git a/wire/lib/src/hive/steps/build.rs b/crates/core/src/hive/steps/build.rs similarity index 100% rename from wire/lib/src/hive/steps/build.rs rename to crates/core/src/hive/steps/build.rs diff --git a/wire/lib/src/hive/steps/cleanup.rs b/crates/core/src/hive/steps/cleanup.rs similarity index 100% rename from wire/lib/src/hive/steps/cleanup.rs rename to crates/core/src/hive/steps/cleanup.rs diff --git a/wire/lib/src/hive/steps/evaluate.rs b/crates/core/src/hive/steps/evaluate.rs similarity index 100% rename from wire/lib/src/hive/steps/evaluate.rs rename to crates/core/src/hive/steps/evaluate.rs diff --git a/wire/lib/src/hive/steps/keys.rs b/crates/core/src/hive/steps/keys.rs similarity index 97% rename from wire/lib/src/hive/steps/keys.rs rename to crates/core/src/hive/steps/keys.rs index fd0887e..5ae702b 100644 --- a/wire/lib/src/hive/steps/keys.rs +++ b/crates/core/src/hive/steps/keys.rs @@ -147,7 +147,7 @@ async fn create_reader(key: &'_ Key) -> Result Result<(key_agent::keys::KeySpec, Vec), KeyError> { +async fn process_key(key: &Key) -> Result<(wire_key_agent::keys::KeySpec, Vec), KeyError> { let mut reader = create_reader(key).await?; let mut buf = Vec::new(); @@ -162,7 +162,7 @@ async fn process_key(key: &Key) -> Result<(key_agent::keys::KeySpec, Vec), K debug!("Staging push to {}", destination.clone().display()); Ok(( - key_agent::keys::KeySpec { + wire_key_agent::keys::KeySpec { length: buf .len() .try_into() @@ -252,7 +252,7 @@ impl ExecuteStep for Keys { return Ok(()); } - let command_string = format!("{agent_directory}/bin/key_agent"); + let command_string = format!("{agent_directory}/bin/wire-key-agent"); let mut child = run_command( &CommandArguments::new(command_string, ctx.modifiers) @@ -297,7 +297,7 @@ impl Keys { async fn select_keys( &self, keys: &Vector, - ) -> Result)>>, HiveLibError> + ) -> Result)>>, HiveLibError> { let futures = keys .iter() diff --git a/wire/lib/src/hive/steps/mod.rs b/crates/core/src/hive/steps/mod.rs similarity index 100% rename from wire/lib/src/hive/steps/mod.rs rename to crates/core/src/hive/steps/mod.rs diff --git a/wire/lib/src/hive/steps/ping.rs b/crates/core/src/hive/steps/ping.rs similarity index 100% rename from wire/lib/src/hive/steps/ping.rs rename to crates/core/src/hive/steps/ping.rs diff --git a/wire/lib/src/hive/steps/push.rs b/crates/core/src/hive/steps/push.rs similarity index 100% rename from wire/lib/src/hive/steps/push.rs rename to crates/core/src/hive/steps/push.rs diff --git a/wire/lib/src/lib.rs b/crates/core/src/lib.rs similarity index 100% rename from wire/lib/src/lib.rs rename to crates/core/src/lib.rs diff --git a/wire/lib/src/status.rs b/crates/core/src/status.rs similarity index 100% rename from wire/lib/src/status.rs rename to crates/core/src/status.rs diff --git a/wire/lib/src/test_macros.rs b/crates/core/src/test_macros.rs similarity index 100% rename from wire/lib/src/test_macros.rs rename to crates/core/src/test_macros.rs diff --git a/wire/lib/src/test_support.rs b/crates/core/src/test_support.rs similarity index 100% rename from wire/lib/src/test_support.rs rename to crates/core/src/test_support.rs diff --git a/wire/key_agent/Cargo.toml b/crates/key_agent/Cargo.toml similarity index 93% rename from wire/key_agent/Cargo.toml rename to crates/key_agent/Cargo.toml index a19c102..041c27d 100644 --- a/wire/key_agent/Cargo.toml +++ b/crates/key_agent/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "key_agent" +name = "wire-key-agent" edition.workspace = true version.workspace = true diff --git a/wire/key_agent/build.rs b/crates/key_agent/build.rs similarity index 100% rename from wire/key_agent/build.rs rename to crates/key_agent/build.rs diff --git a/wire/key_agent/default.nix b/crates/key_agent/default.nix similarity index 55% rename from wire/key_agent/default.nix rename to crates/key_agent/default.nix index 527d714..e31e369 100644 --- a/wire/key_agent/default.nix +++ b/crates/key_agent/default.nix @@ -8,9 +8,9 @@ { packages = { agent = buildRustProgram { - name = "key_agent"; - pname = "wire-tool-key_agent-${system}"; - cargoExtraArgs = "-p key_agent"; + name = "wire-key-agent"; + pname = "wire-tool-key-agent-${system}"; + cargoExtraArgs = "-p wire-key-agent"; }; }; }; diff --git a/wire/key_agent/src/keys.proto b/crates/key_agent/src/keys.proto similarity index 100% rename from wire/key_agent/src/keys.proto rename to crates/key_agent/src/keys.proto diff --git a/wire/key_agent/src/lib.rs b/crates/key_agent/src/lib.rs similarity index 100% rename from wire/key_agent/src/lib.rs rename to crates/key_agent/src/lib.rs diff --git a/wire/key_agent/src/main.rs b/crates/key_agent/src/main.rs similarity index 98% rename from wire/key_agent/src/main.rs rename to crates/key_agent/src/main.rs index dba65d6..14ad3be 100644 --- a/wire/key_agent/src/main.rs +++ b/crates/key_agent/src/main.rs @@ -5,7 +5,6 @@ use base64::Engine; use base64::prelude::BASE64_STANDARD; use futures_util::stream::StreamExt; -use key_agent::keys::KeySpec; use nix::unistd::{Group, User}; use prost::Message; use prost::bytes::Bytes; @@ -16,6 +15,7 @@ use std::path::{Path, PathBuf}; use tokio::fs::File; use tokio::io::AsyncWriteExt; use tokio_util::codec::{FramedRead, LengthDelimitedCodec}; +use wire_key_agent::keys::KeySpec; fn create_path(key_path: &Path) -> Result<(), anyhow::Error> { let prefix = key_path.parent().unwrap(); diff --git a/flake.nix b/flake.nix index 75208af..72a1b4a 100644 --- a/flake.nix +++ b/flake.nix @@ -37,8 +37,8 @@ ./nix/utils.nix # utility functions ./nix/shells.nix ./nix/tests.nix - ./wire/cli - ./wire/key_agent + ./crates/cli + ./crates/key_agent ./doc ./tests/nix ./runtime diff --git a/nix/utils.nix b/nix/utils.nix index 59bbb21..11c6255 100644 --- a/nix/utils.nix +++ b/nix/utils.nix @@ -20,7 +20,7 @@ fileset = unions [ ../.cargo ../.sqlx - ../wire + ../crates ../Cargo.toml ../Cargo.lock ];