MCPcopy Index your code
hub / github.com/jetify-com/devbox / parseStorePathFromInstallableOutput

Function parseStorePathFromInstallableOutput

internal/nix/store.go:78–102  ·  view source on GitHub ↗

parseStorePathFromInstallableOutput parses the output of `nix store path-from-installable --json` into a map of store paths to whether they are in the store. This function is decomposed out of StorePathFromInstallable to make it testable.

(output []byte)

Source from the content-addressed store, hash-verified

76// into a map of store paths to whether they are in the store.
77// This function is decomposed out of StorePathFromInstallable to make it testable.
78func parseStorePathFromInstallableOutput(output []byte) (map[string]bool, error) {
79 result := map[string]bool{}
80
81 // Newer nix versions (like 2.20) have output of the form
82 // {"<store-path>": {}}
83 // Note that values will be null if paths are not in store.
84 var modernPathInfo map[string]any
85 if err := json.Unmarshal(output, &modernPathInfo); err == nil {
86 for path, val := range modernPathInfo {
87 result[path] = val != nil
88 }
89 return result, nil
90 }
91
92 var legacyPathInfos []LegacyPathInfo
93
94 if err := json.Unmarshal(output, &legacyPathInfos); err == nil {
95 for _, outValue := range legacyPathInfos {
96 result[outValue.Path] = outValue.Valid
97 }
98 return result, nil
99 }
100
101 return nil, fmt.Errorf("failed to parse path-info output: %s", output)
102}
103
104// DaemonError reports an unsuccessful attempt to connect to the Nix daemon.
105type DaemonError struct {

Callers 3

StorePathsAreInStoreFunction · 0.85

Calls

no outgoing calls

Tested by 1