Skip to content

Commit d4ee341

Browse files
authored
[easy][bugs] Fix 2 package input bugs (#991)
## Summary Fixes 2 bugs: * Avoid triple slashes that can make comparing urls break when adding flakes (this was affecting correct removal of profile packages and also detecting that they were already installed) * Fix package validation for non-versioned packages (They should use nix search instead of new search service) ## How was it tested? * `devbox add sqlite3` showed error and was not added to devbox.json * In examples/flake/php added and removed packages and confirmed profile remained in sync.
1 parent f1a38b1 commit d4ee341

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

internal/nix/input.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ type Input struct {
2727
func InputFromString(s string, l lock.Locker) *Input {
2828
u, _ := url.Parse(s)
2929
if u.Path == "" && u.Opaque != "" && u.Scheme == "path" {
30-
u.Path = filepath.Join(l.ProjectDir(), u.Opaque)
31-
u.Opaque = ""
30+
// This normalizes url paths to be absolute. It also ensures all
31+
// path urls have a single slash (instead of possibly 3 slashes)
32+
u, _ = url.Parse("path:" + filepath.Join(l.ProjectDir(), u.Opaque))
3233
}
3334
return &Input{*u, l}
3435
}
@@ -136,19 +137,18 @@ func (i *Input) PackageAttributePath() (string, error) {
136137
strings.Join(lo.Keys(infos), ", ")
137138
}
138139
return "", usererr.New(
139-
"Flake \"%s\" is ambiguous. %s",
140+
"Package \"%s\" is ambiguous. %s",
140141
i.String(),
141142
outputs,
142143
)
143144
}
144145

145-
return "", usererr.New("Flake \"%s\" was not found", i.String())
146+
return "", usererr.New("Package \"%s\" was not found", i.String())
146147
}
147148

148149
func (i *Input) urlWithoutFragment() string {
149150
u := i.URL // get copy
150151
u.Fragment = ""
151-
// This will produce urls with extra slashes after the scheme, but that's ok
152152
return u.String()
153153
}
154154

@@ -161,7 +161,7 @@ func (i *Input) hash() string {
161161
}
162162

163163
func (i *Input) validateExists() (bool, error) {
164-
if i.IsDevboxPackage() {
164+
if i.isVersioned() {
165165
version := i.version()
166166
if version == "" && i.isVersioned() {
167167
return false, usererr.New("No version specified for %q.", i.Path)

internal/nix/input_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ func TestInput(t *testing.T) {
2929
{
3030
pkg: "path:path/to/my-flake#my-package",
3131
isFlake: true,
32-
name: "my-flake-c7758d",
33-
urlWithoutFragment: "path://" + filepath.Join(projectDir, "path/to/my-flake"),
34-
urlForInput: "path://" + filepath.Join(projectDir, "path/to/my-flake"),
32+
name: "my-flake-eaedce",
33+
urlWithoutFragment: "path:" + filepath.Join(projectDir, "path/to/my-flake"),
34+
urlForInput: "path:" + filepath.Join(projectDir, "path/to/my-flake"),
3535
},
3636
{
3737
pkg: "path:.#my-package",
3838
isFlake: true,
39-
name: "my-project-744eaa",
40-
urlWithoutFragment: "path://" + projectDir,
41-
urlForInput: "path://" + projectDir,
39+
name: "my-project-bbeb05",
40+
urlWithoutFragment: "path:" + projectDir,
41+
urlForInput: "path:" + projectDir,
4242
},
4343
{
4444
pkg: "path:/tmp/my-project/path/to/my-flake#my-package",

0 commit comments

Comments
 (0)