Skip to content

Commit

Permalink
Allow leaving out initial_stdin setting in config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Luflosi committed Jun 5, 2024
1 parent b4016bc commit 76dcc0f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions nix/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ in
'';
};
initial_stdin = lib.mkOption {
type = lib.types.str;
default = "";
type = lib.types.nullOr lib.types.str;
default = null;
example = lib.literalExpression ''
if cfg.localhost then "server ::1\n" else "";
if cfg.localhost then "server ::1\n" else null;
'';
description = lib.mdDoc ''
String to send to the stdin of the update program before sending anything else.
Expand Down Expand Up @@ -224,7 +224,8 @@ in
startLimitBurst = 1;

serviceConfig = let
settingsFile = settingsFormat.generate "dyndnsd.toml" cfg.settings;
settingsNoNulls = lib.filterAttrsRecursive (_: v: v != null) cfg.settings;
settingsFile = settingsFormat.generate "dyndnsd.toml" settingsNoNulls;
runtimeConfigPath = if cfg.environmentFiles != []
then "/run/${RuntimeDirectory}/dyndnsd.toml"
else settingsFile;
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct Config<'a> {
pub struct UpdateProgram {
pub bin: String,
pub args: Vec<String>,
pub initial_stdin: String,
pub initial_stdin: Option<String>,
pub stdin_per_zone_update: String,
pub final_stdin: String,
pub ipv4: SpecialUpdateProgram,
Expand Down
4 changes: 3 additions & 1 deletion src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ fn splice_ipv6_addrs(prefixlen: u8, prefix: Ipv6Addr, suffix: Ipv6Addr) -> Ipv6A
fn build_command_string(config: &Config, user: &User, q: &QueryParameters) -> String {
// TODO: stream stdin to the process instead of building a string and then pushing it all at once
let mut command = String::new();
command.push_str(config.update_program.initial_stdin.as_str());
if let Some(initial_stdin) = &config.update_program.initial_stdin {
command.push_str(initial_stdin);
}
let domains = &user.domains;
for (domain, props) in domains {
trace!("Domain: {domain:?} {props:?}");
Expand Down

0 comments on commit 76dcc0f

Please sign in to comment.