Skip to content

Commit

Permalink
Return an empty imageID if /run/current/system does not exist on NixO…
Browse files Browse the repository at this point in the history
…S use case

Signed-off-by: Mathieu Grzybek <[email protected]>
  • Loading branch information
mgrzybek committed Jan 8, 2025
1 parent ee7c66b commit 5678be8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions collector/os_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,13 @@ func parseOSRelease(r io.Reader) (*osRelease, error) {
}

func getNixOSImageID() string {
currentSystemSymlink, _ := filepath.EvalSymlinks("/run/current-system")
nixStoreDirectory := strings.Split(currentSystemSymlink, "/")[3]
result := strings.Split(nixStoreDirectory, "-")[0]
var result string
currentSystemSymlink, err := filepath.EvalSymlinks("/run/current-system")

if err == nil {
nixStoreDirectory := strings.Split(currentSystemSymlink, "/")[3]
result = strings.Split(nixStoreDirectory, "-")[0]
}

return result
}
Expand Down

0 comments on commit 5678be8

Please sign in to comment.