--- a/cmds/fleet/Cargo.toml +++ b/cmds/fleet/Cargo.toml @@ -45,10 +45,10 @@ human-repr = { version = "1.1", optional = true } indicatif = { version = "0.18", optional = true } nom = "8.0.0" +opentelemetry = "0.30.0" +opentelemetry_sdk = "0.30.0" tracing-indicatif = { version = "0.3", optional = true } tracing-opentelemetry = "0.31.0" -opentelemetry = "0.30.0" -opentelemetry_sdk = "0.30.0" [features] default = [] --- a/cmds/fleet/src/cmds/tf.rs +++ b/cmds/fleet/src/cmds/tf.rs @@ -38,7 +38,7 @@ { debug!("generating terraform configs"); let system = &config.local_system; - let config = &config.config_field; + let config = &config.flake_outputs; let data = nix_go!(config.tf({ system })); let data: PathBuf = spawn_blocking(move || data.build("out")) .await --- a/crates/fleet-base/src/host.rs +++ b/crates/fleet-base/src/host.rs @@ -34,6 +34,8 @@ pub nix_args: Vec, /// fleet_config.config pub config_field: Value, + /// flake.output + pub flake_outputs: Value, // TODO: Remove with connectivity refactor pub localhost: String, --- a/crates/fleet-base/src/opts.rs +++ b/crates/fleet-base/src/opts.rs @@ -267,6 +267,7 @@ Ok(Config(Arc::new(FleetConfigInternals { directory, data, + flake_outputs: flake, local_system: self.local_system.clone(), nix_args, config_field, --- a/crates/fleet-shared/src/encoding.rs +++ b/crates/fleet-shared/src/encoding.rs @@ -1,5 +1,7 @@ use std::{ - collections::BTreeMap, fmt::{self, Display}, str::FromStr + collections::BTreeMap, + fmt::{self, Display}, + str::FromStr, }; use base64::engine::{Engine, general_purpose::STANDARD_NO_PAD}; --- a/crates/nix-eval/src/logging.cc +++ b/crates/nix-eval/src/logging.cc @@ -9,12 +9,14 @@ bool isVerbose() override { return true; } void log(Verbosity lvl, std::string_view s) override { - rust::Slice str(reinterpret_cast(s.data()), s.size()); + rust::Slice str( + reinterpret_cast(s.data()), s.size()); emit_log(lvl, str); } void logEI(const ErrorInfo &ei) override { auto s = ei.msg.str(); - rust::Slice str(reinterpret_cast(s.data()), s.size()); + rust::Slice str( + reinterpret_cast(s.data()), s.size()); emit_log(ei.level, str); } @@ -27,7 +29,8 @@ b->add_int_field(f.i); } else if (f.type == Logger::Field::tString) { auto s = &f.s; - rust::Slice str(reinterpret_cast(s->data()), s->size()); + rust::Slice str( + reinterpret_cast(s->data()), s->size()); b->add_string_field(str); } else { unreachable(); @@ -45,7 +48,8 @@ b->add_int_field(f.i); } else if (f.type == Logger::Field::tString) { auto s = &f.s; - rust::Slice str(reinterpret_cast(s->data()), s->size()); + rust::Slice str( + reinterpret_cast(s->data()), s->size()); b->add_string_field(str); } else { unreachable(); --- a/flake.lock +++ b/flake.lock @@ -71,6 +71,31 @@ "url": "https://flakehub.com/f/hercules-ci/flake-parts/0.1" } }, + "fleet-tf": { + "inputs": { + "flake-parts": [ + "flake-parts" + ], + "nixpkgs": [ + "nixpkgs" + ], + "shelly": [ + "shelly" + ] + }, + "locked": { + "lastModified": 1759080490, + "owner": "CertainLach", + "repo": "fleet-tf", + "rev": "878bd8c23933d628bf750378bbe527b841901c3d", + "type": "github" + }, + "original": { + "owner": "CertainLach", + "repo": "fleet-tf", + "type": "github" + } + }, "git-hooks-nix": { "inputs": { "flake-compat": "flake-compat", @@ -183,6 +208,7 @@ "inputs": { "crane": "crane", "flake-parts": "flake-parts", + "fleet-tf": "fleet-tf", "nix": "nix", "nixpkgs": "nixpkgs_2", "rust-overlay": "rust-overlay", --- a/flake.nix +++ b/flake.nix @@ -13,6 +13,12 @@ }; crane.url = "github:ipetkov/crane"; shelly.url = "github:CertainLach/shelly"; + fleet-tf = { + url = "github:CertainLach/fleet-tf"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.shelly.follows = "shelly"; + inputs.flake-parts.follows = "flake-parts"; + }; treefmt-nix = { url = "github:numtide/treefmt-nix"; inputs.nixpkgs.follows = "nixpkgs"; @@ -42,7 +48,7 @@ }; flakeModule = flakeModules.default; - fleetModules.tf = ./modules/extras/tf.nix; + flakeModules.fleet-tf = ./modules/extras/tf.nix; # Used to test nix-eval bindings testData = { @@ -114,13 +120,16 @@ { _module.args.pkgs = import inputs.nixpkgs { inherit system; - overlays = [ (inputs.rust-overlay.overlays.default) (final: prev: { - boehmgc = prev.boehmgc.overrideAttrs (prevAttrs: { - configureFlags = prevAttrs.configureFlags ++ [ - "--enable-gc-assertions" - ]; - }); - }) ]; + overlays = [ + (inputs.rust-overlay.overlays.default) + (final: prev: { + boehmgc = prev.boehmgc.overrideAttrs (prevAttrs: { + configureFlags = prevAttrs.configureFlags ++ [ + "--enable-gc-assertions" + ]; + }); + }) + ]; }; # Reference fleet package should be built with nightly rust, specified in rust-toolchain.toml. packages = lib.mkIf deployerSystem ( --- /dev/null +++ b/modules/extras/tf-bootstrap.nix @@ -0,0 +1,37 @@ +{ + lib, + inputs', + pkgs, + config, + ... +}: +let + inherit (lib.options) mkOption mkPackageOption; + inherit (lib.types) listOf package functionTo; +in +{ + options = { + tf.package = mkPackageOption pkgs "terraform" { + extraDescription = "Terraform package to use"; + }; + tf.providers = mkOption { + description = "List of used terraform providers"; + type = functionTo (listOf package); + default = _: [ ]; + }; + tf.finalPackage = mkOption { + description = "Terraform package with all providers"; + type = package; + }; + }; + config = { + tf.finalPackage = inputs'.fleet-tf.packages.terraform-locked.override { + inherit (config.tf) providers; + terraform = config.tf.package; + }; + shelly.shells.default = { + packages = [ config.tf.finalPackage ]; + }; + packages.terraform = config.tf.finalPackage; + }; +} --- a/modules/extras/tf.nix +++ b/modules/extras/tf.nix @@ -11,6 +11,7 @@ inherit (fleetLib.options) mkDataOption; in { + options = { tf = mkOption { type = deferredModule; @@ -18,7 +19,7 @@ module: system: inputs.terranix.lib.terranixConfiguration { inherit system; - pkgs = config.nixpkgs.buildUsing.legacyPackages.${system}; + pkgs = inputs.nixpkgs.legacyPackages.${system}; modules = [ module ]; @@ -35,6 +36,8 @@ }; config = { + flake.tf = config.tf; + tf.output.fleet = { value = { managed = true; @@ -43,6 +46,8 @@ # will be somehow processed by fleet tf. sensitive = true; }; - hosts = config.data.extra.terraformHosts; + fleetConfigurations.default.hosts = config.data.extra.terraformHosts; + + perSystem.imports = [ ./tf-bootstrap.nix ]; }; }