Skip to content

Commit e0d0c06

Browse files
authored
[process-compose] Remove old process compose using store path (#1903)
## Summary Fixes #1901 Alternative: #1902 nix 2.20 removed index support. Use store paths instead. ## How was it tested?
1 parent ff7b1cb commit e0d0c06

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

internal/devbox/devbox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ func (d *Devbox) StartProcessManager(
782782
oldProcessComposePkg := "github:F1bonacc1/process-compose/" + pcVersion + "#defaultPackage." + nix.System()
783783
newProcessComposePkg := "github:F1bonacc1/process-compose/" + processComposeTargetVersion
784784
// Find the old process Compose package
785-
if err := d.removeDevboxUtilityPackage(oldProcessComposePkg); err != nil {
785+
if err := d.removeDevboxUtilityPackage(ctx, oldProcessComposePkg); err != nil {
786786
return err
787787
}
788788

internal/devbox/util.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ package devbox
55

66
import (
77
"context"
8-
"fmt"
98
"io/fs"
109
"os"
1110
"path/filepath"
1211

1312
"github.com/pkg/errors"
1413
"go.jetpack.io/devbox/internal/devpkg"
1514
"go.jetpack.io/devbox/internal/nix"
16-
"go.jetpack.io/devbox/internal/nix/nixprofile"
1715

1816
"go.jetpack.io/devbox/internal/xdg"
1917
)
@@ -47,7 +45,9 @@ func (d *Devbox) addDevboxUtilityPackage(ctx context.Context, pkgName string) er
4745
return nil
4846
}
4947

50-
func (d *Devbox) removeDevboxUtilityPackage(pkgName string) error {
48+
func (d *Devbox) removeDevboxUtilityPackage(
49+
ctx context.Context, pkgName string,
50+
) error {
5151
pkg := devpkg.PackageFromStringWithDefaults(pkgName, d.lockfile)
5252
installables, err := pkg.Installables()
5353
if err != nil {
@@ -59,20 +59,15 @@ func (d *Devbox) removeDevboxUtilityPackage(pkgName string) error {
5959
return err
6060
}
6161

62-
profile, err := nixprofile.ProfileListItems(d.stderr, utilityProfilePath)
63-
if err != nil {
64-
return err
65-
}
66-
6762
for _, installable := range installables {
68-
for i, profileItem := range profile {
69-
if profileItem.MatchesUnlockedReference(installable) {
70-
err = nix.ProfileRemove(utilityProfilePath, fmt.Sprint(i))
71-
if err != nil {
72-
return err
73-
}
74-
// We are done with this installable. Now, remove the next installable:
75-
break
63+
storePaths, err := nix.StorePathsFromInstallable(ctx, installable, false)
64+
if err != nil {
65+
return err
66+
}
67+
68+
for _, storePath := range storePaths {
69+
if err = nix.ProfileRemove(utilityProfilePath, storePath); err != nil {
70+
return err
7671
}
7772
}
7873
}

internal/nix/profiles.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ func ProfileInstall(ctx context.Context, args *ProfileInstallArgs) error {
7575
return cmd.Run()
7676
}
7777

78-
func ProfileRemove(profilePath string, indexes ...string) error {
78+
// ProfileRemove removes packages from a profile.
79+
// WARNING, don't use indexes, they are not supported by nix 2.20+
80+
func ProfileRemove(profilePath string, packageNames ...string) error {
7981
cmd := command(
8082
append([]string{
8183
"profile", "remove",
8284
"--profile", profilePath,
8385
"--impure", // for NIXPKGS_ALLOW_UNFREE
84-
}, indexes...)...,
86+
}, packageNames...)...,
8587
)
8688
cmd.Env = allowUnfreeEnv(allowInsecureEnv(os.Environ()))
8789

0 commit comments

Comments
 (0)