difftreelog
feat experimental opentofu integration
in: trunk
9 files changed
Cargo.lockdiffbeforeafterboth1438 "itertools",1438 "itertools",1439 "nixlike",1439 "nixlike",1440 "r2d2",1440 "r2d2",1441 "regex",1441 "serde",1442 "serde",1442 "serde_json",1443 "serde_json",1443 "thiserror",1444 "thiserror",186618671867[[package]]1868[[package]]1868name = "regex"1869name = "regex"1869version = "1.10.4"1870version = "1.10.6"1870source = "registry+https://github.com/rust-lang/crates.io-index"1871source = "registry+https://github.com/rust-lang/crates.io-index"1871checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c"1872checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619"1872dependencies = [1873dependencies = [1873 "aho-corasick",1874 "aho-corasick",1874 "memchr",1875 "memchr",cmds/fleet/src/cmds/mod.rsdiffbeforeafterboth2pub mod complete;2pub mod complete;3pub mod info;3pub mod info;4pub mod secrets;4pub mod secrets;5pub mod tf;56cmds/fleet/src/cmds/tf.rsdiffbeforeafterbothno changes
cmds/fleet/src/main.rsdiffbeforeafterboth19 complete::Complete,19 complete::Complete,20 info::Info,20 info::Info,21 secrets::Secret,21 secrets::Secret,22 tf::Tf,22};23};23use futures::{future::LocalBoxFuture, stream::FuturesUnordered, TryStreamExt};24use futures::{future::LocalBoxFuture, stream::FuturesUnordered, TryStreamExt};24use host::{Config, FleetOpts};25use host::{Config, FleetOpts};86 /// Command completions87 /// Command completions87 #[clap(hide(true))]88 #[clap(hide(true))]88 Complete(Complete),89 Complete(Complete),90 /// Compile and evaluate terranix configuration91 Tf(Tf),89}92}909391#[derive(Parser)]94#[derive(Parser)]104 Opts::Secret(s) => s.run(config).await?,107 Opts::Secret(s) => s.run(config).await?,105 Opts::Info(i) => i.run(config).await?,108 Opts::Info(i) => i.run(config).await?,106 Opts::Prefetch(p) => p.run(config).await?,109 Opts::Prefetch(p) => p.run(config).await?,110 Opts::Tf(t) => t.run(config).await?,107 // TODO: actually parse commands before starting the async runtime111 // TODO: actually parse commands before starting the async runtime108 Opts::Complete(c) => {112 Opts::Complete(c) => {109 tokio::task::spawn_blocking(move || c.run(RootOpts::command())).await?113 tokio::task::spawn_blocking(move || c.run(RootOpts::command())).await?crates/nix-eval/Cargo.tomldiffbeforeafterboth11itertools = "0.13.0"11itertools = "0.13.0"12nixlike.workspace = true12nixlike.workspace = true13r2d2 = "0.8.10"13r2d2 = "0.8.10"14regex = "1.10.6"14serde = { workspace = true, features = ["derive"] }15serde = { workspace = true, features = ["derive"] }15serde_json.workspace = true16serde_json.workspace = true16thiserror = "1.0.61"17thiserror = "1.0.61"crates/nix-eval/src/session.rsdiffbeforeafterboth12 sync::{mpsc, oneshot, Mutex},12 sync::{mpsc, oneshot, Mutex},13};13};14use tokio_util::codec::{FramedRead, LinesCodec};14use tokio_util::codec::{FramedRead, LinesCodec};15use tracing::{debug, error, warn, Level};15use tracing::{debug, error, info, warn, Level};161617#[derive(Error, Debug)]17#[derive(Error, Debug)]18pub enum Error {18pub enum Error {327 n.parse::<u64>().map_err(Error::Int)327 n.parse::<u64>().map_err(Error::Int)328 }328 }329 async fn execute_expression_string(&mut self, expr: impl AsRef<[u8]>) -> Result<String> {329 async fn execute_expression_string(&mut self, expr: impl AsRef<[u8]>) -> Result<String> {330 // builtins.toJSON escapes some thing in incorrect way, e.g escaped "$" in "\${" is being outputed as "\$",331 // while this escape should be removed as it is intended for nix itself, not for json output.332 //333 // This regex only allows \$ in the beginning of the string, it is easier to implement correctly.334 // TODO: Add peg parser for nix-produced JSON?..335 let regex = regex::Regex::new(r#"(?<prefix>[: {,\[]\\")\\\$"#).expect("fixup json");336330 let num = self.string_wrapping.clone();337 let num = self.string_wrapping.clone();331 let n = self.execute_expression_wrapping(expr, &num).await?;338 let n = self.execute_expression_wrapping(expr, &num).await?;339 let n = regex.replace_all(&n, "$prefix$$");332 let str: String = serde_json::from_str(&n)?;340 let str: String = serde_json::from_str(&n)?;333 Ok(str)341 Ok(str)334 }342 }339 let mut fexpr = b"builtins.toJSON (".to_vec();347 let mut fexpr = b"builtins.toJSON (".to_vec();340 fexpr.extend_from_slice(expr.as_ref());348 fexpr.extend_from_slice(expr.as_ref());341 fexpr.push(b')');349 fexpr.push(b')');350 let s = String::from_utf8_lossy(expr.as_ref());342 let v = self.execute_expression_string(fexpr).await?;351 let v = self.execute_expression_string(fexpr).await?;343 Ok(serde_json::from_str(&v)?)352 Ok(serde_json::from_str(&v)?)344 }353 }flake.nixdiffbeforeafterboth37 };37 };38 flakeModule = flakeModules.default;38 flakeModule = flakeModules.default;3940 fleetModules.tf = ./modules/extras/tf.nix;394140 # To be used with https://github.com/NixOS/nix/pull/889242 # To be used with https://github.com/NixOS/nix/pull/889241 schemas = let43 schemas = letlib/flakePart.nixdiffbeforeafterboth2 fleetLib,2 fleetLib,3 lib,3 lib,4 config,4 config,5 inputs ? {},5 ...6 ...6}: let7}: let7 inherit (lib.options) mkOption;8 inherit (lib.options) mkOption;58 };59 };59 }60 }60 ];61 ];61 specialArgs.fleetLib = import ../lib {62 specialArgs = {63 fleetLib = import ../lib {62 inherit (bootstrapNixpkgs) lib;64 inherit (bootstrapNixpkgs) lib;63 };65 };66 inputs = inputs;67 };64 };68 };65 in69 in66 normalEval70 normalEvalmodules/extras/tf.nixdiffbeforeafterbothno changes