@@ -15,6 +15,7 @@ import (
15
15
const (
16
16
TypeIndirect = "indirect"
17
17
TypePath = "path"
18
+ TypeHttps = "https"
18
19
TypeFile = "file"
19
20
TypeSSH = "ssh"
20
21
TypeGitHub = "github"
@@ -77,49 +78,6 @@ type Ref struct {
77
78
Port int32 `json:port,omitempty`
78
79
}
79
80
80
- // TODO move `ParseRef` to the unit test file. It isn't used anywhere else
81
-
82
- // ParseRef parses a raw flake reference. Nix supports a variety of flake ref
83
- // formats, and isn't entirely consistent about how it parses them. ParseRef
84
- // attempts to mimic how Nix parses flake refs on the command line. The raw ref
85
- // can be one of the following:
86
- //
87
- // - Indirect reference such as "nixpkgs" or "nixpkgs/unstable".
88
- // - Path-like reference such as "./flake" or "/path/to/flake". They must
89
- // start with a '.' or '/' and not contain a '#' or '?'.
90
- // - URL-like reference which must be a valid URL with any special characters
91
- // encoded. The scheme can be any valid flake ref type except for mercurial,
92
- // gitlab, and sourcehut.
93
- //
94
- // ParseRef does not guarantee that a parsed flake ref is valid or that an
95
- // error indicates an invalid flake ref. Use the "nix flake metadata" command or
96
- // the builtins.parseFlakeRef Nix function to validate a flake ref.
97
- func ParseRef (ref string ) (Ref , error ) {
98
- if ref == "" {
99
- return Ref {}, redact .Errorf ("empty flake reference" )
100
- }
101
-
102
- // Handle path-style references first.
103
- parsed := Ref {}
104
- if ref [0 ] == '.' || ref [0 ] == '/' {
105
- if strings .ContainsAny (ref , "?#" ) {
106
- // The Nix CLI does seem to allow paths with a '?'
107
- // (contrary to the manual) but ignores everything that
108
- // comes after it. This is a bit surprising, so we just
109
- // don't allow it at all.
110
- return Ref {}, redact .Errorf ("path-style flake reference %q contains a '?' or '#'" , ref )
111
- }
112
- parsed .Type = TypePath
113
- parsed .Path = ref
114
- return parsed , nil
115
- }
116
- parsed , fragment , err := parseURLRef (ref )
117
- if fragment != "" {
118
- return Ref {}, redact .Errorf ("flake reference %q contains a URL fragment" , ref )
119
- }
120
- return parsed , err
121
- }
122
-
123
81
func parseURLRef (ref string ) (parsed Ref , fragment string , err error ) {
124
82
// A good way to test how Nix parses a flake reference is to run:
125
83
//
0 commit comments