Skip to content

Commit 5b024c2

Browse files
committed
fix: lix version parsing
1 parent 9a48990 commit 5b024c2

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

crates/nix_rs/src/version.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl FromStr for NixVersion {
4343
fn from_str(s: &str) -> Result<Self, Self::Err> {
4444
// NOTE: The parser is lenient in allowing pure nix version (produced
4545
// by [Display] instance), so as to work with serde_with instances.
46-
let re = Regex::new(r"(?:nix \(Nix\) )?(\d+)\.(\d+)\.(\d+)(?:\+(\d+))?$")?;
46+
let re = Regex::new(r"(?m)(?:nix \([^)]*\) )?(\d+)\.(\d+)\.(\d+)(?:\+(\d+))?$")?;
4747

4848
let captures = re.captures(s).ok_or(BadNixVersion::Command)?;
4949
let major = captures[1].parse::<u32>()?;
@@ -124,4 +124,16 @@ async fn test_parse_nix_version() {
124124
patch: 0
125125
})
126126
);
127+
128+
// Parse Lix multi-line version output
129+
assert_eq!(
130+
NixVersion::from_str(
131+
"nix (Lix, like Nix) 2.94.2\nSystem type: x86_64-linux\nFeatures: gc, signed-caches"
132+
),
133+
Ok(NixVersion {
134+
major: 2,
135+
minor: 94,
136+
patch: 2
137+
})
138+
);
127139
}

0 commit comments

Comments
 (0)