2022-06-02 16:39:45 -07:00
|
|
|
mod assets;
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
|
|
|
|
2021-01-24 14:08:48 -08:00
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::io::Write;
|
|
|
|
use std::path::{Path, PathBuf};
|
2021-06-29 01:02:43 -07:00
|
|
|
use std::convert::AsRef;
|
2021-01-24 14:08:48 -08:00
|
|
|
|
|
|
|
use tempfile::{NamedTempFile, TempPath};
|
|
|
|
use tokio::process::Command;
|
2022-06-18 00:07:16 -07:00
|
|
|
use tokio::sync::OnceCell;
|
2021-01-24 14:08:48 -08:00
|
|
|
use serde::Serialize;
|
2021-02-08 18:38:14 -08:00
|
|
|
use validator::Validate;
|
2021-01-24 14:08:48 -08:00
|
|
|
|
|
|
|
use super::{
|
2021-10-25 23:38:10 -07:00
|
|
|
Flake,
|
2022-01-08 01:20:36 -08:00
|
|
|
NixOptions,
|
2021-11-20 23:34:52 -08:00
|
|
|
NodeName,
|
2021-01-24 14:08:48 -08:00
|
|
|
NodeConfig,
|
2021-11-20 23:34:52 -08:00
|
|
|
NodeFilter,
|
2022-01-22 17:50:53 -08:00
|
|
|
NixExpression,
|
2021-12-07 23:13:31 -08:00
|
|
|
ProfileDerivation,
|
2022-06-18 00:07:16 -07:00
|
|
|
StorePath, MetaConfig,
|
2021-01-24 14:08:48 -08:00
|
|
|
};
|
2021-11-20 23:34:52 -08:00
|
|
|
use super::deployment::TargetNode;
|
2022-01-08 01:20:36 -08:00
|
|
|
use crate::error::ColmenaResult;
|
2022-01-08 01:20:36 -08:00
|
|
|
use crate::util::{CommandExecution, CommandExt};
|
2021-11-20 23:34:52 -08:00
|
|
|
use crate::job::JobHandle;
|
2022-06-02 16:39:45 -07:00
|
|
|
use assets::Assets;
|
2021-01-24 14:08:48 -08:00
|
|
|
|
2021-06-29 01:02:43 -07:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum HivePath {
|
2021-10-25 23:38:10 -07:00
|
|
|
/// A Nix Flake.
|
2021-06-29 01:02:43 -07:00
|
|
|
///
|
|
|
|
/// The flake must contain the `colmena` output.
|
2021-10-25 23:38:10 -07:00
|
|
|
Flake(Flake),
|
2021-06-29 01:02:43 -07:00
|
|
|
|
|
|
|
/// A regular .nix file
|
|
|
|
Legacy(PathBuf),
|
|
|
|
}
|
|
|
|
|
2022-01-21 00:45:12 -08:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Hive {
|
|
|
|
/// Path to the hive.
|
|
|
|
path: HivePath,
|
|
|
|
|
|
|
|
/// Path to the context directory.
|
|
|
|
///
|
|
|
|
/// Normally this is directory containing the "hive.nix"
|
|
|
|
/// or "flake.nix".
|
|
|
|
context_dir: Option<PathBuf>,
|
|
|
|
|
2022-06-02 16:39:45 -07:00
|
|
|
/// Static files required to evaluate a Hive configuration.
|
|
|
|
assets: Assets,
|
2022-04-03 19:07:14 -05:00
|
|
|
|
2022-01-21 00:45:12 -08:00
|
|
|
/// Whether to pass --show-trace in Nix commands.
|
|
|
|
show_trace: bool,
|
|
|
|
|
2022-06-18 00:07:16 -07:00
|
|
|
meta_config: OnceCell<MetaConfig>,
|
2022-01-21 00:45:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct NixInstantiate<'hive> {
|
|
|
|
hive: &'hive Hive,
|
|
|
|
expression: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A serialized Nix expression.
|
|
|
|
///
|
|
|
|
/// Very hacky so should be avoided as much as possible. But I suppose it's
|
|
|
|
/// more robust than attempting to generate Nix expressions directly or
|
|
|
|
/// escaping a JSON string to strip off Nix interpolation.
|
|
|
|
struct SerializedNixExpression {
|
|
|
|
json_file: TempPath,
|
|
|
|
}
|
|
|
|
|
2022-01-22 17:50:53 -08:00
|
|
|
/// An expression to evaluate the system profiles of selected nodes.
|
|
|
|
struct EvalSelectedExpression<'hive> {
|
|
|
|
hive: &'hive Hive,
|
|
|
|
nodes_expr: SerializedNixExpression,
|
|
|
|
}
|
|
|
|
|
2021-06-29 01:02:43 -07:00
|
|
|
impl HivePath {
|
2022-01-08 01:20:36 -08:00
|
|
|
pub async fn from_path<P: AsRef<Path>>(path: P) -> ColmenaResult<Self> {
|
2021-06-29 01:02:43 -07:00
|
|
|
let path = path.as_ref();
|
|
|
|
|
|
|
|
if let Some(osstr) = path.file_name() {
|
|
|
|
if osstr == "flake.nix" {
|
2021-10-25 23:38:10 -07:00
|
|
|
let parent = path.parent().unwrap();
|
|
|
|
let flake = Flake::from_dir(parent).await?;
|
|
|
|
return Ok(Self::Flake(flake));
|
2021-06-29 01:02:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-25 23:38:10 -07:00
|
|
|
Ok(Self::Legacy(path.to_owned()))
|
2021-06-29 01:02:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn context_dir(&self) -> Option<PathBuf> {
|
|
|
|
match self {
|
|
|
|
Self::Legacy(p) => {
|
2021-10-25 23:38:10 -07:00
|
|
|
p.parent().map(|d| d.to_owned())
|
|
|
|
}
|
|
|
|
Self::Flake(flake) => {
|
|
|
|
flake.local_dir().map(|d| d.to_owned())
|
2021-06-29 01:02:43 -07:00
|
|
|
}
|
2021-06-29 01:02:43 -07:00
|
|
|
}
|
|
|
|
}
|
2021-06-29 01:02:43 -07:00
|
|
|
}
|
|
|
|
|
2021-01-24 14:08:48 -08:00
|
|
|
impl Hive {
|
2022-01-08 01:20:36 -08:00
|
|
|
pub fn new(path: HivePath) -> ColmenaResult<Self> {
|
2021-06-29 01:02:43 -07:00
|
|
|
let context_dir = path.context_dir();
|
|
|
|
|
2022-06-18 00:07:16 -07:00
|
|
|
Ok(Self{
|
2021-06-29 01:02:43 -07:00
|
|
|
path,
|
|
|
|
context_dir,
|
2022-06-02 16:39:45 -07:00
|
|
|
assets: Assets::new(),
|
2021-01-24 14:08:48 -08:00
|
|
|
show_trace: false,
|
2022-06-18 00:07:16 -07:00
|
|
|
meta_config: OnceCell::new(),
|
2021-01-24 14:08:48 -08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-06-29 01:02:43 -07:00
|
|
|
pub fn context_dir(&self) -> Option<&Path> {
|
|
|
|
self.context_dir.as_ref().map(|p| p.as_ref())
|
|
|
|
}
|
|
|
|
|
2022-06-18 00:07:16 -07:00
|
|
|
pub async fn get_meta_config(&self) -> ColmenaResult<&MetaConfig> {
|
|
|
|
self.meta_config.get_or_try_init(||async {
|
|
|
|
self.nix_instantiate("hive.metaConfig").eval()
|
|
|
|
.capture_json().await
|
|
|
|
}).await
|
|
|
|
}
|
|
|
|
|
2021-06-29 01:02:43 -07:00
|
|
|
pub fn set_show_trace(&mut self, value: bool) {
|
2021-01-24 14:08:48 -08:00
|
|
|
self.show_trace = value;
|
|
|
|
}
|
|
|
|
|
2022-01-08 01:20:36 -08:00
|
|
|
/// Returns Nix options to set for this Hive.
|
|
|
|
pub fn nix_options(&self) -> NixOptions {
|
|
|
|
let mut options = NixOptions::default();
|
|
|
|
options.set_show_trace(self.show_trace);
|
|
|
|
options
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns Nix options to set for this Hive, with configured remote builders.
|
|
|
|
pub async fn nix_options_with_builders(&self) -> ColmenaResult<NixOptions> {
|
|
|
|
let mut options = NixOptions::default();
|
|
|
|
options.set_show_trace(self.show_trace);
|
2021-04-09 23:43:31 -07:00
|
|
|
|
2022-06-18 00:07:16 -07:00
|
|
|
if let Some(machines_file) = &self.get_meta_config().await?.machines_file {
|
2022-01-08 01:20:36 -08:00
|
|
|
options.set_builders(Some(format!("@{}", machines_file)));
|
2021-04-09 23:43:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(options)
|
|
|
|
}
|
|
|
|
|
2021-11-20 23:34:52 -08:00
|
|
|
/// Convenience wrapper to filter nodes for CLI actions.
|
2022-01-08 01:20:36 -08:00
|
|
|
pub async fn select_nodes(&self, filter: Option<NodeFilter>, ssh_config: Option<PathBuf>, ssh_only: bool) -> ColmenaResult<HashMap<NodeName, TargetNode>> {
|
2021-11-20 23:34:52 -08:00
|
|
|
let mut node_configs = None;
|
|
|
|
|
|
|
|
log::info!("Enumerating nodes...");
|
|
|
|
|
|
|
|
let all_nodes = self.node_names().await?;
|
|
|
|
let selected_nodes = match filter {
|
|
|
|
Some(filter) => {
|
|
|
|
if filter.has_node_config_rules() {
|
|
|
|
log::debug!("Retrieving deployment info for all nodes...");
|
|
|
|
|
|
|
|
let all_node_configs = self.deployment_info().await?;
|
|
|
|
let filtered = filter.filter_node_configs(all_node_configs.iter())
|
|
|
|
.into_iter().collect();
|
|
|
|
|
|
|
|
node_configs = Some(all_node_configs);
|
|
|
|
|
|
|
|
filtered
|
|
|
|
} else {
|
|
|
|
filter.filter_node_names(&all_nodes)?
|
|
|
|
.into_iter().collect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => all_nodes.clone(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let n_selected = selected_nodes.len();
|
|
|
|
|
|
|
|
let mut node_configs = if let Some(configs) = node_configs {
|
|
|
|
configs
|
|
|
|
} else {
|
|
|
|
log::debug!("Retrieving deployment info for selected nodes...");
|
|
|
|
self.deployment_info_selected(&selected_nodes).await?
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut targets = HashMap::new();
|
|
|
|
let mut n_ssh = 0;
|
|
|
|
for node in selected_nodes.into_iter() {
|
|
|
|
let config = node_configs.remove(&node).unwrap();
|
|
|
|
|
|
|
|
let host = config.to_ssh_host().map(|mut host| {
|
|
|
|
n_ssh += 1;
|
|
|
|
|
|
|
|
if let Some(ssh_config) = &ssh_config {
|
|
|
|
host.set_ssh_config(ssh_config.clone());
|
|
|
|
}
|
|
|
|
host.upcast()
|
|
|
|
});
|
|
|
|
let ssh_host = host.is_some();
|
|
|
|
let target = TargetNode::new(node.clone(), host, config);
|
|
|
|
|
|
|
|
if !ssh_only || ssh_host {
|
|
|
|
targets.insert(node, target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let skipped = n_selected - n_ssh;
|
|
|
|
|
|
|
|
if targets.is_empty() {
|
|
|
|
if skipped != 0 {
|
|
|
|
log::warn!("No hosts selected.");
|
|
|
|
} else {
|
|
|
|
log::warn!("No hosts selected ({} skipped).", skipped);
|
|
|
|
}
|
|
|
|
} else if targets.len() == all_nodes.len() {
|
|
|
|
log::info!("Selected all {} nodes.", targets.len());
|
|
|
|
} else if !ssh_only || skipped == 0 {
|
|
|
|
log::info!("Selected {} out of {} hosts.", targets.len(), all_nodes.len());
|
|
|
|
} else {
|
|
|
|
log::info!("Selected {} out of {} hosts ({} skipped).", targets.len(), all_nodes.len(), skipped);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(targets)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a list of all node names.
|
2022-01-08 01:20:36 -08:00
|
|
|
pub async fn node_names(&self) -> ColmenaResult<Vec<NodeName>> {
|
2021-11-20 23:34:52 -08:00
|
|
|
self.nix_instantiate("attrNames hive.nodes").eval()
|
|
|
|
.capture_json().await
|
|
|
|
}
|
|
|
|
|
2021-03-18 15:03:58 -07:00
|
|
|
/// Retrieve deployment info for all nodes.
|
2022-01-08 01:20:36 -08:00
|
|
|
pub async fn deployment_info(&self) -> ColmenaResult<HashMap<NodeName, NodeConfig>> {
|
2021-12-07 23:13:31 -08:00
|
|
|
let configs: HashMap<NodeName, NodeConfig> = self.nix_instantiate("hive.deploymentConfig").eval_with_builders().await?
|
2021-01-24 14:08:48 -08:00
|
|
|
.capture_json().await?;
|
|
|
|
|
2021-02-08 18:38:14 -08:00
|
|
|
for config in configs.values() {
|
|
|
|
config.validate()?;
|
|
|
|
for key in config.keys.values() {
|
|
|
|
key.validate()?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(configs)
|
2021-01-24 14:08:48 -08:00
|
|
|
}
|
|
|
|
|
2021-03-18 15:03:58 -07:00
|
|
|
/// Retrieve deployment info for a single node.
|
2022-04-19 00:29:35 -07:00
|
|
|
#[cfg_attr(not(target_os = "linux"), allow(dead_code))]
|
2022-01-08 01:20:36 -08:00
|
|
|
pub async fn deployment_info_single(&self, node: &NodeName) -> ColmenaResult<Option<NodeConfig>> {
|
2022-01-01 16:41:35 -08:00
|
|
|
let expr = format!("hive.nodes.\"{}\".config.deployment or null", node.as_str());
|
|
|
|
self.nix_instantiate(&expr).eval_with_builders().await?
|
|
|
|
.capture_json().await
|
2021-03-18 15:03:58 -07:00
|
|
|
}
|
|
|
|
|
2021-11-20 23:34:52 -08:00
|
|
|
/// Retrieve deployment info for a list of nodes.
|
2022-01-08 01:20:36 -08:00
|
|
|
pub async fn deployment_info_selected(&self, nodes: &[NodeName]) -> ColmenaResult<HashMap<NodeName, NodeConfig>> {
|
2022-01-21 00:45:12 -08:00
|
|
|
let nodes_expr = SerializedNixExpression::new(nodes)?;
|
2021-11-20 23:34:52 -08:00
|
|
|
|
2021-12-07 23:13:31 -08:00
|
|
|
let configs: HashMap<NodeName, NodeConfig> = self.nix_instantiate(&format!("hive.deploymentConfigSelected {}", nodes_expr.expression()))
|
2021-11-20 23:34:52 -08:00
|
|
|
.eval_with_builders().await?
|
|
|
|
.capture_json().await?;
|
|
|
|
|
|
|
|
for config in configs.values() {
|
|
|
|
config.validate()?;
|
|
|
|
for key in config.keys.values() {
|
|
|
|
key.validate()?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(configs)
|
|
|
|
}
|
|
|
|
|
2021-01-24 14:08:48 -08:00
|
|
|
/// Evaluates selected nodes.
|
|
|
|
///
|
|
|
|
/// Evaluation may take up a lot of memory, so we make it possible
|
|
|
|
/// to split up the evaluation process into chunks and run them
|
|
|
|
/// concurrently with other processes (e.g., build and apply).
|
2022-01-08 01:20:36 -08:00
|
|
|
pub async fn eval_selected(&self, nodes: &[NodeName], job: Option<JobHandle>) -> ColmenaResult<HashMap<NodeName, ProfileDerivation>> {
|
2022-01-21 00:45:12 -08:00
|
|
|
let nodes_expr = SerializedNixExpression::new(nodes)?;
|
2021-01-28 23:58:54 -08:00
|
|
|
|
2022-01-21 00:45:12 -08:00
|
|
|
let expr = format!("hive.evalSelectedDrvPaths {}", nodes_expr.expression());
|
2021-07-13 01:38:12 -07:00
|
|
|
|
2021-12-07 23:13:31 -08:00
|
|
|
let command = self.nix_instantiate(&expr)
|
|
|
|
.eval_with_builders().await?;
|
2021-02-09 19:28:45 -08:00
|
|
|
let mut execution = CommandExecution::new(command);
|
2021-11-20 23:34:52 -08:00
|
|
|
execution.set_job(job);
|
2021-12-07 23:13:31 -08:00
|
|
|
execution.set_hide_stdout(true);
|
|
|
|
|
|
|
|
execution
|
|
|
|
.capture_json::<HashMap<NodeName, StorePath>>().await?
|
|
|
|
.into_iter().map(|(name, path)| {
|
|
|
|
let path = path.into_derivation()?;
|
|
|
|
Ok((name, path))
|
|
|
|
})
|
|
|
|
.collect()
|
2021-01-24 14:08:48 -08:00
|
|
|
}
|
|
|
|
|
2022-01-22 17:50:53 -08:00
|
|
|
/// Returns the expression to evaluate selected nodes.
|
|
|
|
pub fn eval_selected_expr(&self, nodes: &[NodeName]) -> ColmenaResult<impl NixExpression + '_> {
|
|
|
|
let nodes_expr = SerializedNixExpression::new(nodes)?;
|
|
|
|
|
|
|
|
Ok(EvalSelectedExpression {
|
|
|
|
hive: self,
|
|
|
|
nodes_expr,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-01-08 01:20:36 -08:00
|
|
|
/// Evaluates an expression using values from the configuration.
|
2022-01-08 01:20:36 -08:00
|
|
|
pub async fn introspect(&self, expression: String, instantiate: bool) -> ColmenaResult<String> {
|
2021-10-28 14:09:35 -07:00
|
|
|
if instantiate {
|
|
|
|
let expression = format!("hive.introspect ({})", expression);
|
|
|
|
self.nix_instantiate(&expression).instantiate_with_builders().await?
|
|
|
|
.capture_output().await
|
|
|
|
} else {
|
|
|
|
let expression = format!("toJSON (hive.introspect ({}))", expression);
|
|
|
|
self.nix_instantiate(&expression).eval_with_builders().await?
|
|
|
|
.capture_json().await
|
|
|
|
}
|
2021-01-24 14:08:48 -08:00
|
|
|
}
|
|
|
|
|
2022-01-21 00:45:12 -08:00
|
|
|
/// Returns the base expression from which the evaluated Hive can be used.
|
|
|
|
fn get_base_expression(&self) -> String {
|
2022-06-02 16:39:45 -07:00
|
|
|
self.assets.get_base_expression(self.path())
|
2022-01-21 00:45:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns whether this Hive is a flake.
|
|
|
|
fn is_flake(&self) -> bool {
|
|
|
|
matches!(self.path(), HivePath::Flake(_))
|
|
|
|
}
|
|
|
|
|
2021-01-24 14:08:48 -08:00
|
|
|
fn nix_instantiate(&self, expression: &str) -> NixInstantiate {
|
2021-11-23 13:33:23 -08:00
|
|
|
NixInstantiate::new(self, expression.to_owned())
|
2021-01-24 14:08:48 -08:00
|
|
|
}
|
2021-06-29 01:02:43 -07:00
|
|
|
|
|
|
|
fn path(&self) -> &HivePath {
|
|
|
|
&self.path
|
|
|
|
}
|
2021-01-24 14:08:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'hive> NixInstantiate<'hive> {
|
|
|
|
fn new(hive: &'hive Hive, expression: String) -> Self {
|
|
|
|
Self {
|
|
|
|
hive,
|
|
|
|
expression,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-08 01:20:36 -08:00
|
|
|
fn instantiate(&self) -> Command {
|
2021-01-24 14:08:48 -08:00
|
|
|
let mut command = Command::new("nix-instantiate");
|
2021-06-29 01:02:43 -07:00
|
|
|
|
2022-01-21 00:45:12 -08:00
|
|
|
if self.hive.is_flake() {
|
|
|
|
command.args(&["--experimental-features", "flakes"]);
|
2021-06-29 01:02:43 -07:00
|
|
|
}
|
2021-01-24 14:08:48 -08:00
|
|
|
|
2022-01-21 00:45:12 -08:00
|
|
|
let mut full_expression = self.hive.get_base_expression();
|
|
|
|
full_expression += &self.expression;
|
|
|
|
|
|
|
|
command
|
|
|
|
.arg("--no-gc-warning")
|
|
|
|
.arg("-E")
|
|
|
|
.arg(&full_expression);
|
|
|
|
|
2021-01-24 14:08:48 -08:00
|
|
|
command
|
|
|
|
}
|
|
|
|
|
|
|
|
fn eval(self) -> Command {
|
|
|
|
let mut command = self.instantiate();
|
2022-01-08 01:20:36 -08:00
|
|
|
let options = self.hive.nix_options();
|
2021-12-07 23:13:31 -08:00
|
|
|
command.arg("--eval").arg("--json").arg("--strict")
|
|
|
|
// Ensures the derivations are instantiated
|
|
|
|
// Required for system profile evaluation and IFD
|
2022-01-08 01:20:36 -08:00
|
|
|
.arg("--read-write-mode")
|
|
|
|
.args(options.to_args());
|
2021-01-24 14:08:48 -08:00
|
|
|
command
|
|
|
|
}
|
2021-07-13 01:38:12 -07:00
|
|
|
|
2022-01-08 01:20:36 -08:00
|
|
|
async fn instantiate_with_builders(self) -> ColmenaResult<Command> {
|
2022-01-08 01:20:36 -08:00
|
|
|
let options = self.hive.nix_options_with_builders().await?;
|
2021-07-13 01:38:12 -07:00
|
|
|
let mut command = self.instantiate();
|
|
|
|
|
2022-01-08 01:20:36 -08:00
|
|
|
command.args(options.to_args());
|
2021-07-13 01:38:12 -07:00
|
|
|
|
|
|
|
Ok(command)
|
|
|
|
}
|
|
|
|
|
2022-01-08 01:20:36 -08:00
|
|
|
async fn eval_with_builders(self) -> ColmenaResult<Command> {
|
2022-01-08 01:20:36 -08:00
|
|
|
let options = self.hive.nix_options_with_builders().await?;
|
2021-07-13 01:38:12 -07:00
|
|
|
let mut command = self.eval();
|
|
|
|
|
2022-01-08 01:20:36 -08:00
|
|
|
command.args(options.to_args());
|
2021-07-13 01:38:12 -07:00
|
|
|
|
|
|
|
Ok(command)
|
|
|
|
}
|
2021-01-24 14:08:48 -08:00
|
|
|
}
|
|
|
|
|
2022-01-21 00:45:12 -08:00
|
|
|
impl SerializedNixExpression {
|
2022-01-08 01:20:36 -08:00
|
|
|
pub fn new<T>(data: T) -> ColmenaResult<Self> where T: Serialize {
|
2021-01-24 14:08:48 -08:00
|
|
|
let mut tmp = NamedTempFile::new()?;
|
|
|
|
let json = serde_json::to_vec(&data).expect("Could not serialize data");
|
|
|
|
tmp.write_all(&json)?;
|
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
json_file: tmp.into_temp_path(),
|
|
|
|
})
|
|
|
|
}
|
2022-01-22 17:50:53 -08:00
|
|
|
}
|
2021-01-24 14:08:48 -08:00
|
|
|
|
2022-01-22 17:50:53 -08:00
|
|
|
impl NixExpression for SerializedNixExpression {
|
|
|
|
fn expression(&self) -> String {
|
2021-01-24 14:08:48 -08:00
|
|
|
format!("(builtins.fromJSON (builtins.readFile {}))", self.json_file.to_str().unwrap())
|
|
|
|
}
|
|
|
|
}
|
2022-01-22 17:50:53 -08:00
|
|
|
|
|
|
|
impl<'hive> NixExpression for EvalSelectedExpression<'hive> {
|
|
|
|
fn expression(&self) -> String {
|
|
|
|
format!(
|
|
|
|
"{} hive.evalSelected {}",
|
|
|
|
self.hive.get_base_expression(),
|
|
|
|
self.nodes_expr.expression(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn requires_flakes(&self) -> bool {
|
|
|
|
self.hive.is_flake()
|
|
|
|
}
|
|
|
|
}
|