Skip to content

Commit 862bebe

Browse files
authored
[plugins] Ensure plugin flakes get upgraded on every install (#1687)
## Summary Run `nix profile upgrade` on any virtenv (plugin) flakes after any package is installed. This is a bit blunt, but works. (ideally we determine which plugin is being touched and we only upgrade that flake, but that's a bit tricky) Fixes #1680 ## How was it tested? ```bash devbox add php devbox add php82Extensions.xdebug devbox run php -m | grep xdebug ```
1 parent 458e555 commit 862bebe

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

examples/development/php/php8.1/devbox.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
},
4343
4444
"last_modified": "2023-09-04T16:24:30Z",
45-
"plugin_version": "0.0.2",
45+
"plugin_version": "0.0.3",
4646
"resolved": "github:NixOS/nixpkgs/3c15feef7770eb5500a4b8792623e2d6f598c9c1#php81",
4747
"source": "devbox-search",
4848
"version": "8.1.23",

internal/devpkg/package.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ func (p *Package) Installable() (string, error) {
285285
return installable, nil
286286
}
287287

288+
// FlakeInstallable returns a flake installable. The raw string must contain
289+
// a valid flake reference parsable by ParseFlakeRef, optionally followed by an
290+
// #attrpath and/or an ^output.
291+
func (p *Package) FlakeInstallable() (FlakeInstallable, error) {
292+
return ParseFlakeInstallable(p.Raw)
293+
}
294+
288295
// urlForInstall is used during `nix profile install`.
289296
// The key difference with URLForFlakeInput is that it has a suffix of
290297
// `#attributePath`

internal/impl/packages.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,12 @@ func (d *Devbox) syncPackagesToProfile(ctx context.Context, mode installMode) er
375375

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

internal/plugin/manager.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
package plugin
55

66
import (
7+
"path/filepath"
8+
"strings"
9+
710
"github.com/samber/lo"
811
"go.jetpack.io/devbox/internal/devpkg"
912
"go.jetpack.io/devbox/internal/lock"
@@ -74,3 +77,7 @@ func (m *Manager) ProcessPluginPackages(
7477
// priority field to the config.
7578
return append(pluginPackages, netUserPackages...), nil
7679
}
80+
81+
func (m *Manager) PathIsInVirtenv(absPath string) bool {
82+
return strings.HasPrefix(absPath, filepath.Join(m.ProjectDir(), VirtenvPath))
83+
}

0 commit comments

Comments
 (0)