Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Process Compose to 0.85.0 #1820

Merged
merged 9 commits into from
Feb 22, 2024
Merged

Update Process Compose to 0.85.0 #1820

merged 9 commits into from
Feb 22, 2024

Conversation

Lagoja
Copy link
Contributor

@Lagoja Lagoja commented Feb 17, 2024

Summary

Devbox will now install process-compose 0.85.0 if an older version (or no version) is installed on the user's system

If an older version of process compose was installed in the utility profile, Devbox will remove that older version first. This PR provides a general way to remove packages (either from Flakes or Nixpkgs) from the utils profile

This PR also fixes a bug where using devbox services up with the --config flag would cause process compose to fail.

This PR doesn't add any new 0.85.0 features, though that could be a follow up.

How was it tested?

  • Install an older version in the utils profile, check that this upgrades
  • Remove process-compose from the utlis profile, check that 0.85.0 is installed
  • This should be pre-released first, for more extensive testing

internal/devbox/devbox.go Outdated Show resolved Hide resolved
@@ -14,7 +14,7 @@ import (
"github.com/f1bonacc1/process-compose/src/types"
)

type processStates = types.ProcessStates
type processStates = types.ProcessesState
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this still the same type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be. Everything still seems to compile and work as expected.

internal/services/manager.go Outdated Show resolved Hide resolved
@@ -32,14 +35,66 @@ func (d *Devbox) addDevboxUtilityPackage(ctx context.Context, pkgName string) er
return err
}

return nixprofile.ProfileInstall(ctx, &nixprofile.ProfileInstallArgs{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If nixprofile.ProfileInstall and nixprofile.ProfileInstallArgs are no longer used you should remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a little confused about having both nixprofile and nix.profile. Is nix.profile the one we should keep using? Can we completely remove nixprofile?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nixprofile.ProfileInstall wraps nix.ProfileInstall printing a "Step message" and showing nicer error messages. I think for your use case, using nix.ProfileInstall is fine.

In 06fd5ff @savil switched from using nixprofile.ProfileInstall to nix.ProfileInstall because he handles the messaging outside of the function call. In that case we can get rid of nixprofile.ProfileInstall. @savil please confirm

Comment on lines 57 to 64
profileString, err := nix.ProfileList(d.stderr, utilityProfilePath, true)
if err != nil {
return err
}

if err = json.Unmarshal([]byte(profileString), &utilProfile); err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use nixprofile.ProfileListItems which handles legacy nix outputs. It may also simplify finding the index.

Edit: actually, you can use ProfileListNameOrIndex to find the index.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure why we have nixprofile and nix.profile in the source code, but both of those methods you mentioned seem to require that we have a lockfile, which does not exist in the case of the utility profile (since we're manipulating the profile directly, instead of using Devbox).

I think we'd need to either refactor those methods to not require a profile, or refactor the utility profile to use Devbox.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went with using ProfileListItems to get the list, and then doing a quick match based on unlockedReference == installable. This should work for utility packages that we install from a Flake reference and not from a store path, which is currently the case for all utility packages.

internal/nix/profiles.go Outdated Show resolved Hide resolved
@@ -32,14 +35,66 @@ func (d *Devbox) addDevboxUtilityPackage(ctx context.Context, pkgName string) er
return err
}

return nixprofile.ProfileInstall(ctx, &nixprofile.ProfileInstallArgs{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nixprofile.ProfileInstall wraps nix.ProfileInstall printing a "Step message" and showing nicer error messages. I think for your use case, using nix.ProfileInstall is fine.

In 06fd5ff @savil switched from using nixprofile.ProfileInstall to nix.ProfileInstall because he handles the messaging outside of the function call. In that case we can get rid of nixprofile.ProfileInstall. @savil please confirm

@@ -142,6 +142,16 @@ func readManifest(profilePath string) (manifest, error) {

const DefaultPriority = 5

type NixProfile struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

Comment on lines 164 to 168
if args.Lockfile != nil {
for _, item := range items {
if item.Matches(args.Package, args.Lockfile) {
return item.NameOrIndex(), nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert? This function won't really work for flakes without the lockfile.

I think we can fix this dependency, but out of scope for this PR.

internal/nix/nixprofile/item.go Outdated Show resolved Hide resolved
Comment on lines 71 to 78
func findUtilPackage(installable string, profile []*nixprofile.NixProfileListItem) int {
for i := range profile {
if profile[i].MatchesInstallable(installable) {
return i
}
}
return -1
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's probably best to keep this function in removeDevboxUtilityPackage.

As written, this is not really limited to util packages.

So

for i, profileItem := range profile {
  if profileItem.MatchesInstallable(installable) {
    return nix.ProfileRemove(utilityProfilePath, fmt.Sprint(i))
  }
}
return nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's much better

@Lagoja Lagoja merged commit 9411a3e into main Feb 22, 2024
24 checks passed
@Lagoja Lagoja deleted the jl/process-compose-85 branch February 22, 2024 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants