Skip to content
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
1 change: 0 additions & 1 deletion examples/development/php/php8.1/devbox.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"packages": [
"php81Packages.composer@latest",
"php81Extensions.xdebug@latest",
"php81Extensions.imagick@latest",
"php@8.1"
Expand Down
20 changes: 0 additions & 20 deletions examples/development/php/php8.1/devbox.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 1 addition & 8 deletions internal/impl/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 22 additions & 6 deletions internal/plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package plugin

import (
"github.com/samber/lo"
"go.jetpack.io/devbox/internal/devpkg"
"go.jetpack.io/devbox/internal/lock"
)
Expand Down Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions internal/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions plugins/haskell.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"__packages": [
"path:{{ .Virtenv }}"
],
"__remove_trigger_package": true,
"create_files": {
"{{ .Virtenv }}/flake.nix": "haskell/flake.nix"
}
Expand Down
1 change: 1 addition & 0 deletions plugins/mariadb.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"__packages": [
"path:{{ .Virtenv }}"
],
"__remove_trigger_package": true,
"shell": {
"init_hook": [
"bash {{ .Virtenv }}/setup_db.sh"
Expand Down
1 change: 1 addition & 0 deletions plugins/mysql.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"__packages": [
"path:{{ .Virtenv }}"
],
"__remove_trigger_package": true,
"shell": {
"init_hook": [
"bash {{ .Virtenv }}/setup_db.sh"
Expand Down
1 change: 1 addition & 0 deletions plugins/php.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down