Skip to content

Commit

Permalink
transformer: derive pname and version from store path
Browse files Browse the repository at this point in the history
  • Loading branch information
nikstur committed Mar 8, 2024
1 parent 902d24a commit d4cffb6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rust/transformer/src/derivation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@ pub struct Derivation {

impl Derivation {
pub fn new(store_path: &str) -> Self {
// Because we only have the store path we have to derive the pname and version from it
let stripped = store_path.strip_prefix("/nix/store/");
let pname = stripped
.and_then(|s| s.split('-').nth(1))
.map(ToOwned::to_owned);
let version = stripped
.and_then(|s| s.split('-').last())
.map(ToOwned::to_owned);

Self {
path: store_path.to_string(),
pname,
version,
..Self::default()
}
}
Expand Down

0 comments on commit d4cffb6

Please sign in to comment.