diff --git a/module/template.nix b/module/template.nix index 8d1a823..6cf35a5 100644 --- a/module/template.nix +++ b/module/template.nix @@ -29,6 +29,10 @@ let Content of the template ''; }; + trim = (mkEnableOption { }) // { + default = true; + description = "remove trailing and leading whitespace of the secret content to insert"; + }; name = mkOption { type = types.str; default = submod.config._module.args.name; diff --git a/src/cmd/deploy.rs b/src/cmd/deploy.rs index 3346b9a..536a48b 100644 --- a/src/cmd/deploy.rs +++ b/src/cmd/deploy.rs @@ -247,15 +247,26 @@ impl Profile { let mut template = t.content.clone(); let hashstrs_of_it = t.parse_hash_str_list().expect("parse template"); + let trim_the_insertial = t.trim; + hashstr_ctx_map .iter() .filter(|(k, _)| hashstrs_of_it.contains(k)) .for_each(|(k, v)| { - // render + // render and insert trace!("template before process: {}", template); + + let raw_composed_insertial = String::from_utf8_lossy(v).to_string(); + + let insertial = if trim_the_insertial { + raw_composed_insertial.trim() + } else { + raw_composed_insertial.as_str() + }; + template = template.replace( format!("{{{{ {} }}}}", hex::encode(k.as_slice())).as_str(), - String::from_utf8_lossy(v).to_string().as_str(), + insertial, ); }); diff --git a/src/profile.rs b/src/profile.rs index 0807340..dc1b5a2 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -28,6 +28,7 @@ pub struct Secret { pub struct Template { pub name: String, pub content: String, + pub trim: bool, pub group: String, pub mode: String, pub owner: String,