fix: pass hostname as a quoted string (#243)
This commit is contained in:
parent
c6850451ef
commit
7ae6c9fa22
1 changed files with 14 additions and 1 deletions
|
|
@ -102,7 +102,7 @@ fn find_flake_attr(flake_uri: &str, nix_options: &NixOptions) -> Result<String>
|
|||
}
|
||||
|
||||
let hostname_os = nix::unistd::gethostname()?;
|
||||
let hostname = hostname_os.to_string_lossy();
|
||||
let hostname = escape_nix_string(&hostname_os.to_string_lossy());
|
||||
let default = "default";
|
||||
|
||||
if let Some(full_uri) = try_flake_attr(flake, &hostname, nix_options, &system)? {
|
||||
|
|
@ -113,6 +113,19 @@ fn find_flake_attr(flake_uri: &str, nix_options: &NixOptions) -> Result<String>
|
|||
anyhow::bail!("No suitable flake attribute found, giving up.");
|
||||
}
|
||||
|
||||
fn escape_nix_string(s: &str) -> String {
|
||||
let mut out = String::with_capacity(s.len() + 2);
|
||||
out.push('"');
|
||||
let mut i = 0;
|
||||
for (j, _) in s.match_indices(['"', '\\']) {
|
||||
out += &s[i..j];
|
||||
i = j;
|
||||
}
|
||||
out += &s[i..];
|
||||
out.push('"');
|
||||
out
|
||||
}
|
||||
|
||||
fn try_flake_attr(
|
||||
flake: &str,
|
||||
attr: &str,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue