-
-
Notifications
You must be signed in to change notification settings - Fork 74
cleanup installable #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
cleanup installable #445
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,10 +86,7 @@ impl DarwinRebuildArgs { | |
| Some(r) => r.to_owned(), | ||
| None => return Err(eyre!("NH_DARWIN_FLAKE missing reference part")), | ||
| }; | ||
| let attribute = elems | ||
| .next() | ||
| .map(crate::installable::parse_attribute) | ||
| .unwrap_or_default(); | ||
| let attribute = elems.next().unwrap_or_default().to_string(); | ||
|
|
||
| Installable::Flake { | ||
| reference, | ||
|
|
@@ -107,8 +104,7 @@ impl DarwinRebuildArgs { | |
| // If user explicitly selects some other attribute, don't push | ||
| // darwinConfigurations | ||
| if attribute.is_empty() { | ||
| attribute.push(String::from("darwinConfigurations")); | ||
| attribute.push(hostname.clone()); | ||
| *attribute = format!("darwinConfigurations.{hostname}"); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -205,10 +201,7 @@ impl DarwinReplArgs { | |
| Some(r) => r.to_owned(), | ||
| None => return Err(eyre!("NH_DARWIN_FLAKE missing reference part")), | ||
| }; | ||
| let attribute = elems | ||
| .next() | ||
| .map(crate::installable::parse_attribute) | ||
| .unwrap_or_default(); | ||
| let attribute = elems.next().unwrap_or_default().to_string(); | ||
|
|
||
| Installable::Flake { | ||
| reference, | ||
|
|
@@ -229,8 +222,7 @@ impl DarwinReplArgs { | |
| } = target_installable | ||
| { | ||
| if attribute.is_empty() { | ||
| attribute.push(String::from("darwinConfigurations")); | ||
| attribute.push(hostname); | ||
| *attribute = format!("darwinConfigurations.{hostname}"); | ||
| } | ||
|
Comment on lines
222
to
226
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same quoting issue leaks into REPL. The REPL path has the same 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,10 +69,7 @@ impl HomeRebuildArgs { | |
| Some(r) => r.to_owned(), | ||
| None => return Err(eyre!("NH_HOME_FLAKE missing reference part")), | ||
| }; | ||
| let attribute = elems | ||
| .next() | ||
| .map(crate::installable::parse_attribute) | ||
| .unwrap_or_default(); | ||
| let attribute = elems.next().unwrap_or_default().to_string(); | ||
|
|
||
| Installable::Flake { | ||
| reference, | ||
|
|
@@ -223,7 +220,7 @@ where | |
| return Ok(res); | ||
| } | ||
|
|
||
| attribute.push(String::from("homeConfigurations")); | ||
| *attribute = String::from("homeConfigurations"); | ||
|
|
||
|
Comment on lines
+223
to
224
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix attrpath construction (compile errors + incorrect paths).
Apply targeted changes: @@
- *attribute = String::from("homeConfigurations");
+ *attribute = String::from("homeConfigurations");
@@
- attribute.push_str(&config_name);
- if push_drv {
- attribute.extend(toplevel.clone());
- }
+ attribute = format!("{attribute}.{}", quote_attr_segment(&config_name));
+ if push_drv {
+ attribute.push_str(".config.home.activationPackage");
+ }
@@
- let tried_attr_path = {
- let mut attr_path = attribute.clone();
- attr_path.push_str(&config_name);
- Installable::Flake {
- reference: flake_reference,
- attribute: attr_path,
- }
- .to_args()
- .join(" ")
- };
+ let tried_attr_path = {
+ let attr_path = format!("{attribute}.{}", quote_attr_segment(&config_name));
+ Installable::Flake {
+ reference: flake_reference,
+ attribute: attr_path,
+ }
+ .to_args()
+ .join(" ")
+ };
@@
- let current_try_attr = {
- let mut attr_path = attribute.clone();
- attr_path.push_str(&attr_name);
- attr_path
- };
+ let current_try_attr =
+ format!("{attribute}.{}", quote_attr_segment(&attr_name));
@@
- attribute.push_str(&attr_name);
- if push_drv {
- attribute.extend(toplevel.clone());
- }
+ attribute = format!("{attribute}.{}", quote_attr_segment(&attr_name));
+ if push_drv {
+ attribute.push_str(".config.home.activationPackage");
+ }
@@
- Installable::File {
- ref mut attribute, ..
- } => {
- if push_drv {
- attribute.extend(toplevel);
- }
- },
+ Installable::File { ref mut attribute, .. } => {
+ if push_drv {
+ attribute.push_str(".config.home.activationPackage");
+ }
+ },
@@
- Installable::Expression {
- ref mut attribute, ..
- } => {
- if push_drv {
- attribute.extend(toplevel);
- }
- },
+ Installable::Expression { ref mut attribute, .. } => {
+ if push_drv {
+ attribute.push_str(".config.home.activationPackage");
+ }
+ },Add once in this module: fn quote_attr_segment(s: &str) -> String {
let needs_quotes = s.is_empty()
|| s.chars().any(|c| !(c.is_ascii_alphanumeric() || c == '_' || c == '-' || c == '\'')); // dot not allowed in bare names
if needs_quotes {
let escaped = s.replace('"', "\\\"");
format!(r#""{}""#, escaped)
} else {
s.to_string()
}
}Optional cleanup (outside ranges): drop the now-unused Also applies to: 254-257, 263-271, 309-311, 318-321, 351-361 🤖 Prompt for AI Agents |
||
| let flake_reference = reference.clone(); | ||
| let mut found_config = false; | ||
|
|
@@ -254,7 +251,7 @@ where | |
| if check_res.map(|s| s.trim().to_owned()).as_deref() == Some("true") { | ||
| debug!("Using explicit configuration from flag: {config_name:?}"); | ||
|
|
||
| attribute.push(config_name); | ||
| attribute.push_str(&config_name); | ||
| if push_drv { | ||
| attribute.extend(toplevel.clone()); | ||
| } | ||
|
|
@@ -264,7 +261,7 @@ where | |
| // Explicit config provided but not found | ||
| let tried_attr_path = { | ||
| let mut attr_path = attribute.clone(); | ||
| attr_path.push(config_name); | ||
| attr_path.push_str(&config_name); | ||
| Installable::Flake { | ||
| reference: flake_reference, | ||
| attribute: attr_path, | ||
|
|
@@ -309,7 +306,7 @@ where | |
|
|
||
| let current_try_attr = { | ||
| let mut attr_path = attribute.clone(); | ||
| attr_path.push(attr_name.clone()); | ||
| attr_path.push_str(&attr_name); | ||
| attr_path | ||
| }; | ||
| tried.push(current_try_attr.clone()); | ||
|
|
@@ -318,7 +315,7 @@ where | |
| check_res.map(|s| s.trim().to_owned()).as_deref() | ||
| { | ||
| debug!("Using automatically detected configuration: {}", attr_name); | ||
| attribute.push(attr_name); | ||
| attribute.push_str(&attr_name); | ||
| if push_drv { | ||
| attribute.extend(toplevel.clone()); | ||
| } | ||
|
|
@@ -379,10 +376,7 @@ impl HomeReplArgs { | |
| Some(r) => r.to_owned(), | ||
| None => return Err(eyre!("NH_HOME_FLAKE missing reference part")), | ||
| }; | ||
| let attribute = elems | ||
| .next() | ||
| .map(crate::installable::parse_attribute) | ||
| .unwrap_or_default(); | ||
| let attribute = elems.next().unwrap_or_default().to_string(); | ||
|
|
||
| Installable::Flake { | ||
| reference, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote hostname when building the attrpath.
format!("darwinConfigurations.{hostname}")breaks as soon as the hostname contains dots or other characters that need quoting (e.g. the default macOS*.local). We previously relied onjoin_attributeto emitdarwinConfigurations."myhost.local". Without that quoting, Nix resolves the wrong attribute and the rebuild fails.Please reintroduce the quoting helper (or escape the hostname) so that we emit a valid attrpath for all hostnames.
🤖 Prompt for AI Agents