diff --git a/examples/development/php/php8.1/devbox.json b/examples/development/php/php8.1/devbox.json index 4b6f2849940..c3243a776a8 100644 --- a/examples/development/php/php8.1/devbox.json +++ b/examples/development/php/php8.1/devbox.json @@ -1,6 +1,5 @@ { "packages": [ - "php81Packages.composer@latest", "php81Extensions.xdebug@latest", "php81Extensions.imagick@latest", "php@8.1" diff --git a/examples/development/php/php8.1/devbox.lock b/examples/development/php/php8.1/devbox.lock index 66389caea3e..fba3ff2b709 100644 --- a/examples/development/php/php8.1/devbox.lock +++ b/examples/development/php/php8.1/devbox.lock @@ -40,26 +40,6 @@ } } }, - "php81Packages.composer@latest": { - "last_modified": "2023-08-30T00:25:28Z", - "resolved": "github:NixOS/nixpkgs/a63a64b593dcf2fe05f7c5d666eb395950f36bc9#php81Packages.composer", - "source": "devbox-search", - "version": "2.5.8", - "systems": { - "aarch64-darwin": { - "store_path": "/nix/store/7hxmkxa9bmaplyy1ixl0yxv3j0qvxvc3-php-composer-2.5.8" - }, - "aarch64-linux": { - "store_path": "/nix/store/vwrbpz9wr7blr7alx0fl3x79ym3jbdqa-php-composer-2.5.8" - }, - "x86_64-darwin": { - "store_path": "/nix/store/fjy357jpj9q2bfahsgnak4mrh8y07izw-php-composer-2.5.8" - }, - "x86_64-linux": { - "store_path": "/nix/store/6w2vrfjdwhr3mj1magr2rmbycln379f8-php-composer-2.5.8" - } - } - }, "php@8.1": { "last_modified": "2023-09-04T16:24:30Z", "plugin_version": "0.0.2", diff --git a/internal/impl/devbox.go b/internal/impl/devbox.go index e45dbb4163f..47327ab1551 100644 --- a/internal/impl/devbox.go +++ b/internal/impl/devbox.go @@ -963,14 +963,7 @@ func (d *Devbox) InstallablePackages() []*devpkg.Package { // packages concatenated in correct order func (d *Devbox) AllInstallablePackages() ([]*devpkg.Package, error) { userPackages := d.InstallablePackages() - pluginPackages, err := d.PluginManager().PluginPackages(userPackages) - if err != nil { - return nil, err - } - // We prioritize plugin packages so that the php plugin works. Not sure - // if this is behavior we want for user plugins. We may need to add an optional - // priority field to the config. - return append(pluginPackages, userPackages...), nil + return d.PluginManager().ProcessPluginPackages(userPackages) } func (d *Devbox) Includes() []plugin.Includable { diff --git a/internal/plugin/manager.go b/internal/plugin/manager.go index bbc14ad3ffa..282d58a3db7 100644 --- a/internal/plugin/manager.go +++ b/internal/plugin/manager.go @@ -4,6 +4,7 @@ package plugin import ( + "github.com/samber/lo" "go.jetpack.io/devbox/internal/devpkg" "go.jetpack.io/devbox/internal/lock" ) @@ -45,16 +46,31 @@ func (m *Manager) ApplyOptions(opts ...managerOption) { } } -func (m *Manager) PluginPackages(inputs []*devpkg.Package) ([]*devpkg.Package, error) { - result := []*devpkg.Package{} - for _, input := range inputs { - config, err := getConfigIfAny(input, m.ProjectDir()) +// ProcessPluginPackages adds and removes packages as indicated by plugins +func (m *Manager) ProcessPluginPackages( + userPackages []*devpkg.Package, +) ([]*devpkg.Package, error) { + pluginPackages := []*devpkg.Package{} + packagesToRemove := []*devpkg.Package{} + for _, pkg := range userPackages { + config, err := getConfigIfAny(pkg, m.ProjectDir()) if err != nil { return nil, err } else if config == nil { continue } - result = append(result, devpkg.PackageFromStrings(config.Packages, m.lockfile)...) + pluginPackages = append( + pluginPackages, + devpkg.PackageFromStrings(config.Packages, m.lockfile)..., + ) + if config.RemoveTriggerPackage { + packagesToRemove = append(packagesToRemove, pkg) + } } - return result, nil + + netUserPackages, _ := lo.Difference(userPackages, packagesToRemove) + // We prioritize plugin packages so that the php plugin works. Not sure + // if this is behavior we want for user plugins. We may need to add an optional + // priority field to the config. + return append(pluginPackages, netUserPackages...), nil } diff --git a/internal/plugin/plugin.go b/internal/plugin/plugin.go index 9552bdebfd8..68b0503a005 100644 --- a/internal/plugin/plugin.go +++ b/internal/plugin/plugin.go @@ -43,6 +43,9 @@ type config struct { Packages []string `json:"__packages"` Env map[string]string `json:"env"` Readme string `json:"readme"` + // If true, we remove the package that triggered this plugin from the environment + // Useful when we want to replace with flake + RemoveTriggerPackage bool `json:"__remove_trigger_package,omitempty"` Shell struct { // InitHook contains commands that will run at shell startup. diff --git a/plugins/haskell.json b/plugins/haskell.json index e87d25b4b40..33122393797 100644 --- a/plugins/haskell.json +++ b/plugins/haskell.json @@ -5,6 +5,7 @@ "__packages": [ "path:{{ .Virtenv }}" ], + "__remove_trigger_package": true, "create_files": { "{{ .Virtenv }}/flake.nix": "haskell/flake.nix" } diff --git a/plugins/mariadb.json b/plugins/mariadb.json index d32b8c95551..3750b7a50ac 100644 --- a/plugins/mariadb.json +++ b/plugins/mariadb.json @@ -18,6 +18,7 @@ "__packages": [ "path:{{ .Virtenv }}" ], + "__remove_trigger_package": true, "shell": { "init_hook": [ "bash {{ .Virtenv }}/setup_db.sh" diff --git a/plugins/mysql.json b/plugins/mysql.json index 6ce809f184e..75bd335751b 100644 --- a/plugins/mysql.json +++ b/plugins/mysql.json @@ -18,6 +18,7 @@ "__packages": [ "path:{{ .Virtenv }}" ], + "__remove_trigger_package": true, "shell": { "init_hook": [ "bash {{ .Virtenv }}/setup_db.sh" diff --git a/plugins/php.json b/plugins/php.json index feb839c0c2f..620c3168352 100644 --- a/plugins/php.json +++ b/plugins/php.json @@ -6,6 +6,7 @@ "path:{{ .Virtenv }}", "path:{{ .Virtenv }}#composer" ], + "__remove_trigger_package": true, "env": { "PHPFPM_ERROR_LOG_FILE": "{{ .Virtenv }}/php-fpm.log", "PHPFPM_PID_FILE": "{{ .Virtenv }}/php-fpm.pid",