ParseInstallable parses a flake installable. The raw string must contain a valid flake reference parsable by [ParseRef], optionally followed by an #attrpath and/or an ^output.
(raw string)
| 645 | // a valid flake reference parsable by [ParseRef], optionally followed by an |
| 646 | // #attrpath and/or an ^output. |
| 647 | func ParseInstallable(raw string) (Installable, error) { |
| 648 | if raw == "" { |
| 649 | return Installable{}, redact.Errorf("empty flake installable") |
| 650 | } |
| 651 | |
| 652 | // The output spec must be parsed and removed first, otherwise it will |
| 653 | // be parsed as part of the flake ref's URL fragment. |
| 654 | install := Installable{} |
| 655 | raw, install.Outputs = splitOutputSpec(raw) |
| 656 | install.Outputs = strings.Join(install.SplitOutputs(), ",") // clean the outputs |
| 657 | |
| 658 | // Interpret installables with path-style flake refs as URLs to extract |
| 659 | // the attribute path (fragment). This means that path-style flake refs |
| 660 | // cannot point to files with a '#' or '?' in their name, since those |
| 661 | // would be parsed as the URL fragment or query string. This mimic's |
| 662 | // Nix's CLI behavior. |
| 663 | if raw[0] == '.' || raw[0] == '/' { |
| 664 | raw = "path:" + raw |
| 665 | } |
| 666 | |
| 667 | var err error |
| 668 | install.Ref, install.AttrPath, err = parseURLRef(raw) |
| 669 | if err != nil { |
| 670 | return Installable{}, err |
| 671 | } |
| 672 | return install, nil |
| 673 | } |
| 674 | |
| 675 | // SplitOutputs splits and sorts the comma-separated list of outputs. It skips |
| 676 | // any empty outputs. If one or more of the outputs is a "*", then the result |