Skip to content

Commit

Permalink
+
Browse files Browse the repository at this point in the history
  • Loading branch information
oluceps committed Dec 12, 2024
1 parent aa35c2a commit 508a1fe
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/cmd/check.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::PathBuf;

use eyre::{Context, ContextCompat, Result, eyre};
use log::debug;

Expand All @@ -6,13 +8,13 @@ use crate::util::secmap::{RencBuilder, RencCtx};
use super::renc::CompleteProfile;

impl CompleteProfile<'_> {
pub fn check(&self) -> Result<()> {
pub fn check(&self, flake_root: PathBuf) -> Result<()> {
let profile = self
.inner_ref()
.first()
.with_context(|| eyre::eyre!("deploy must only one host"))?;

let ctx = RencCtx::create(self)?;
let ctx = RencCtx::create(self, Some(flake_root))?;

let inst = RencBuilder::create(self)
.build_instore()
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Profile {
let templates = self.templates.iter().filter(|i| if_early(i.0));

let complete = CompleteProfile::from_iter(iter::once(self));
let ctx = RencCtx::create(&complete)?;
let ctx = RencCtx::create(&complete, None)?;

let plain_map = RencBuilder::create(&complete)
.build_instore()
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fs, path::PathBuf};

use eyre::{eyre, Context, ContextCompat};
use eyre::{Context, ContextCompat, eyre};
use log::info;
use renc::CompleteProfile;
use {argh::FromArgs, std::fmt::Debug};
Expand Down Expand Up @@ -123,7 +123,7 @@ impl Args {
SubCmd::Check(_) => {
info!("start checking");
let profile = profile()?;
CompleteProfile::from_iter(&profile).check()?;
CompleteProfile::from_iter(&profile).check(flake_root)?;
info!("check complete");
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/renc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<'a> CompleteProfile<'a> {
bail!("`flake.nix` not found here, make sure run in flake toplevel.");
};

let ctx = RencCtx::create(&self)?;
let ctx = RencCtx::create(&self, None)?;
let mut materia = RencBuilder::create(&self).build_inrepo(&ctx, cache_path.clone());
materia.clean_outdated(cache_path)?;
materia.retain_noexist();
Expand Down
30 changes: 21 additions & 9 deletions src/util/secmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,34 @@ impl<'a, B> RencCtx<'a, B> {
}

impl<'a> RencCtx<'a, AgeEnc> {
pub fn create(material: &'a CompleteProfile) -> Result<Self> {
pub fn create(material: &'a CompleteProfile, flake_root: Option<PathBuf>) -> Result<Self> {
let c: DashMap<&Secret, Result<SecBuf<AgeEnc>>> = material
.inner_ref()
.iter()
.flat_map(|x| x.secrets.values())
.map(|i| {
let file = {
let file_pathbuf = PathBuf::from(&i.file);

if flake_root.is_some() && file_pathbuf.is_relative() {
let mut flake_root = flake_root.clone().expect("yes");
flake_root.push(file_pathbuf);
flake_root
} else {
file_pathbuf
}
};
(
i,
PathBuf::from(i.file.clone())
.canonicalize()
.wrap_err_with(|| eyre!("secret not found: {}", i.file))
.and_then(|i| {
SecPathBuf::<InStore>::from(&i)
.read_buffer()
.map(SecBuf::new)
}),
({
file.canonicalize()
.wrap_err_with(|| eyre!("secret not found: {}", i.file))
.and_then(|i| {
SecPathBuf::<InStore>::from(&i)
.read_buffer()
.map(SecBuf::new)
})
}),
)
})
.collect();
Expand Down

0 comments on commit 508a1fe

Please sign in to comment.