Skip to content

[plugins] Ensure plugin flakes get upgraded on every install #1687

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

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/development/php/php8.1/devbox.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"[email protected]": {
"last_modified": "2023-09-04T16:24:30Z",
"plugin_version": "0.0.2",
"plugin_version": "0.0.3",
"resolved": "github:NixOS/nixpkgs/3c15feef7770eb5500a4b8792623e2d6f598c9c1#php81",
"source": "devbox-search",
"version": "8.1.23",
Expand Down
7 changes: 7 additions & 0 deletions internal/devpkg/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ func (p *Package) Installable() (string, error) {
return installable, nil
}

// FlakeInstallable returns a flake installable. The raw string must contain
// a valid flake reference parsable by ParseFlakeRef, optionally followed by an
// #attrpath and/or an ^output.
func (p *Package) FlakeInstallable() (FlakeInstallable, error) {
return ParseFlakeInstallable(p.Raw)
}

// urlForInstall is used during `nix profile install`.
// The key difference with URLForFlakeInput is that it has a suffix of
// `#attributePath`
Expand Down
10 changes: 8 additions & 2 deletions internal/impl/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,12 @@ func (d *Devbox) syncPackagesToProfile(ctx context.Context, mode installMode) er

// Last, find the pending packages, and ensure they are added to the nix-profile
// Important to maintain the order of packages as specified by
// Devbox.InstallablePackages() (higher priority first)
// Devbox.InstallablePackages() (higher priority first).
// We also run nix profile upgrade on any virtenv flakes. This is a bit of a
// blunt approach, but ensured any plugin created flakes are up-to-date.
pending := []*devpkg.Package{}
for _, pkg := range packages {
_, err := nixprofile.ProfileListIndex(&nixprofile.ProfileListIndexArgs{
idx, err := nixprofile.ProfileListIndex(&nixprofile.ProfileListIndexArgs{
Items: itemsToKeep,
Lockfile: d.lockfile,
Writer: d.stderr,
Expand All @@ -390,6 +392,10 @@ func (d *Devbox) syncPackagesToProfile(ctx context.Context, mode installMode) er
return err
}
pending = append(pending, pkg)
} else if f, err := pkg.FlakeInstallable(); err == nil && d.pluginManager.PathIsInVirtenv(f.Ref.Path) {
if err := nix.ProfileUpgrade(profileDir, idx); err != nil {
return err
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions internal/plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
package plugin

import (
"path/filepath"
"strings"

"github.com/samber/lo"
"go.jetpack.io/devbox/internal/devpkg"
"go.jetpack.io/devbox/internal/lock"
Expand Down Expand Up @@ -74,3 +77,7 @@ func (m *Manager) ProcessPluginPackages(
// priority field to the config.
return append(pluginPackages, netUserPackages...), nil
}

func (m *Manager) PathIsInVirtenv(absPath string) bool {
return strings.HasPrefix(absPath, filepath.Join(m.ProjectDir(), VirtenvPath))
}