Skip to content
Open
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
11 changes: 10 additions & 1 deletion .schema/devbox.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,16 @@
},
"env_from": {
"type": "string"
},
"nixpkgs": {
"type": "object",
"properties": {
"commit": {
"type": "string",
"description": "The commit hash of the nixpkgs repository to use"
}
}
}
},
"additionalProperties": false
}
}
7 changes: 6 additions & 1 deletion docs/app/docs/devbox_examples/databases/mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ MYSQL_BASEDIR=.devbox/nix/profile/default
MYSQL_HOME=./.devbox/virtenv/mysql/run
MYSQL_DATADIR=./.devbox/virtenv/mysql/data
MYSQL_UNIX_PORT=./.devbox/virtenv/mysql/run/mysql.sock
MYSQL_PID_FILE=./.devbox/mysql/run/mysql.pid
MYSQL_PID_FILE=./.devbox/virtenv/mysql/run/mysql.pid
MYSQL_CONF=./devbox.d/mysql/my.cnf
```

### Files

The following helper file will be created in your project directory:

* \{PROJECT_DIR\}/devbox.d/mysql/my.cnf

The plugin will also create the following helper files in your project's `.devbox/virtenv` folder:

* mysql/flake.nix
Expand Down
56 changes: 37 additions & 19 deletions docs/app/docs/devbox_examples/languages/elixir.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,59 @@
title: Elixir
---

Elixir can be configured to install Hex and Rebar dependencies in a local directory. This will keep Elixir from trying to install in your immutable Nix Store:
Elixir can be installed by simply running `devbox add elixir`. This will automatically include the Elixir Plugin to isolate Mix/Hex artifacts and enable shell history in `iex`.

[**Example Repo**](https://github.com/jetify-com/devbox/tree/main/examples/development/elixir/elixir_hello)

[![Open In Devspace](../../../static/img/open-in-devspace.svg)](https://auth.jetify.com/devspace/templates/elixir/)

## Adding Elixir to your project

`devbox add elixir bash`, or add the following to your `devbox.json`
`devbox add elixir`, or add the following to your `devbox.json`

```json
"packages": [
"elixir@latest",
"bash@latest"
"elixir@latest"
],
```

This will install the latest version of Elixir available. You can find other installable versions of Elixir by running `devbox search elixir`. You can also search for Elixir on [Nixhub](https://www.nixhub.io/packages/elixir)
This will install the latest version of Elixir. You can find other installable versions of Elixir by running `devbox search elixir`. You can also search for Elixir on [Nixhub](https://www.nixhub.io/packages/elixir)

## Installing Hex and Rebar locally
## Elixir Plugin Support

Since you are unable to install Elixir Deps directly into the Nix store, you will need to configure mix to install your dependencies globally. You can do this by adding the following lines to your `devbox.json` init_hook:
Devbox will automatically use the following configuration when you install Elixir with `devbox add`.

### Environment Variables

`$MIX_HOME` and `$HEX_HOME` configure Mix/Hex to install artifacts locally, while `$ERL_AFLAGS` enables shell history in `iex`:

```bash
MIX_HOME={PROJECT_DIR}/.devbox/virtenv/elixir/mix
HEX_HOME={PROJECT_DIR}/.devbox/virtenv/elixir/hex
ERL_AFLAGS="-kernel shell_history enabled"
```

### Disabling the Elixir Plugin

You can disable the Elixir plugin by running `devbox add elixir --disable-plugin`, or by setting the `disable_plugin` field in your `devbox.json`:

```json
"shell": {
"init_hook": [
"mkdir -p .nix-mix",
"mkdir -p .nix-hex",
"export MIX_HOME=$PWD/.nix-mix",
"export HEX_HOME=$PWD/.nix-hex",
"export ERL_AFLAGS='-kernel shell_history enabled'",
"mix local.hex --force",
"mix local.rebar --force"
]
}
{
"packages": {
"elixir": {
"version": "latest",
"disable_plugin": true
}
},
}
```

This will create local folders and force mix to install your Hex and Rebar packages to those folders. Now when you are in `devbox shell`, you can install using `mix deps`.
Note that disabling the plugin will cause Mix and Hex to cache artifacts globally in the user's home directory (at `~/.mix/` and `~/.hex/`). This might actually be preferable if you're developing several Elixir projects and want to benefit from caching, but does defeat the isolation guarantees of Devbox.

If the plugin is disabled, it's recommended to manually set `$ERL_AFLAGS` to preserve `iex` shell history:

```json
"env": {
"ERL_AFLAGS": "-kernel shell_history enabled"
}
```
5 changes: 4 additions & 1 deletion docs/app/docs/guides/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This doc describes how to use Devbox Plugins with your project. **Plugins** prov

### Built-in Plugins

If you add one of the packages listed above to your project using `devbox add <pkg>`, Devbox will automatically activate the plugin for that package.
If you add one of the packages listed below to your project using `devbox add <pkg>`, Devbox will automatically activate the plugin for that package.

You can also explicitly add a built-in plugin in your project by adding it to the [`include` section](../configuration.md#include) of your `devbox.json` file. For example, to explicitly add the plugin for Nginx, you can add the following to your `devbox.json` file:

Expand All @@ -34,6 +34,7 @@ Built-in plugins are available for the following packages. You can activate the
* [PHP](../devbox_examples/languages/php.md) (php, php80, php81, php82...)
* [Python](../devbox_examples/languages/python.md) (python, python-full, python-minimal...)
* [Ruby](../devbox_examples/languages/ruby.md)(ruby, ruby_3_1, ruby_3_0...)
* [Elixir](../devbox_examples/languages/elixir.md)(elixir, elixir_1_16, elixir_1_15...)


### Local Plugins
Expand All @@ -56,6 +57,8 @@ Sometimes, you may want to share a plugin across multiple projects or users. In
]
```

Note that Devbox will cache Github plugins for 24 hours. This is to aid performance of `devbox shell` and similar commands, and avoids downloading the plugin from Github each time. In extenuating circumstances, you can bypass this cache by setting `export DEVBOX_X_GITHUB_PLUGIN_CACHE_TTL=<time>` , where time is a valid input to `time.ParseDuration` (see [doc](https://pkg.go.dev/time#ParseDuration)) such as "120s" or "2m".

## An Example of a Plugin: Nginx
Let's take a look at the plugin for Nginx. To get started, let's initialize a new devbox project, and add the `nginx` package:

Expand Down
15 changes: 3 additions & 12 deletions examples/development/elixir/elixir_hello/devbox.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
{
"packages": {
"elixir": "latest"
},
"env": {
"MIX_HOME": "$PWD/.nix-mix",
"HEX_HOME": "$PWD/.nix-hex",
"ERL_AFLAGS": "-kernel shell_history enabled"
},
"packages": [
"elixir@latest"
],
"shell": {
"init_hook": [
"mkdir -p .nix-mix",
"mkdir -p .nix-hex",
"mix local.hex --force",
"mix local.rebar --force",
"mix deps.get"
],
"scripts": {
Expand Down
23 changes: 12 additions & 11 deletions examples/development/elixir/elixir_hello/devbox.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,51 @@
"lockfile_version": "1",
"packages": {
"elixir@latest": {
"last_modified": "2024-02-10T18:15:24Z",
"resolved": "github:NixOS/nixpkgs/10b813040df67c4039086db0f6eaf65c536886c6#elixir",
"last_modified": "2024-11-28T07:51:56Z",
"plugin_version": "0.0.1",
"resolved": "github:NixOS/nixpkgs/226216574ada4c3ecefcbbec41f39ce4655f78ef#elixir",
"source": "devbox-search",
"version": "1.15.7",
"version": "1.17.3",
"systems": {
"aarch64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/kf294q6pwmqv8hb5ivis509y1wjjgm09-elixir-1.15.7",
"path": "/nix/store/91w79z55qsjkhnbs3a21l3h27va98mf6-elixir-1.17.3",
"default": true
}
],
"store_path": "/nix/store/kf294q6pwmqv8hb5ivis509y1wjjgm09-elixir-1.15.7"
"store_path": "/nix/store/91w79z55qsjkhnbs3a21l3h27va98mf6-elixir-1.17.3"
},
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/f5x2w7df45vahjcpjf76dv101il8xq98-elixir-1.15.7",
"path": "/nix/store/pz4hk0sp4zj76waaprlfdmvc4xdblz55-elixir-1.17.3",
"default": true
}
],
"store_path": "/nix/store/f5x2w7df45vahjcpjf76dv101il8xq98-elixir-1.15.7"
"store_path": "/nix/store/pz4hk0sp4zj76waaprlfdmvc4xdblz55-elixir-1.17.3"
},
"x86_64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/6vv8qlvhpi62nk5d06lhi5isvlg7bcj9-elixir-1.15.7",
"path": "/nix/store/gnjg57wv71svvqw7s3rxyjc6lkps2r95-elixir-1.17.3",
"default": true
}
],
"store_path": "/nix/store/6vv8qlvhpi62nk5d06lhi5isvlg7bcj9-elixir-1.15.7"
"store_path": "/nix/store/gnjg57wv71svvqw7s3rxyjc6lkps2r95-elixir-1.17.3"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/dlq14nswvq479pmnrwlyn2hyk6cwp65a-elixir-1.15.7",
"path": "/nix/store/rx7qr8bar4qldx6yg3njvm8hn84d3yyk-elixir-1.17.3",
"default": true
}
],
"store_path": "/nix/store/dlq14nswvq479pmnrwlyn2hyk6cwp65a-elixir-1.15.7"
"store_path": "/nix/store/rx7qr8bar4qldx6yg3njvm8hn84d3yyk-elixir-1.17.3"
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/fatih/color v1.17.0
github.com/fsnotify/fsnotify v1.7.0
github.com/getsentry/sentry-go v0.28.0
github.com/go-jose/go-jose/v4 v4.0.2
github.com/go-jose/go-jose/v4 v4.0.4
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/hashicorp/go-envparse v0.1.0
Expand All @@ -44,7 +44,7 @@ require (
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8
golang.org/x/mod v0.18.0
golang.org/x/oauth2 v0.21.0
golang.org/x/sync v0.7.0
golang.org/x/sync v0.10.0
golang.org/x/tools v0.22.0
gopkg.in/yaml.v3 v3.0.1
)
Expand Down Expand Up @@ -128,9 +128,9 @@ require (
github.com/ulikunitz/xz v0.5.12 // indirect
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/term v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
)
24 changes: 12 additions & 12 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 29 additions & 2 deletions internal/boxcli/list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Jetify Inc. and contributors. All rights reserved.
// Copyright 2025 Jetify Inc. and contributors. All rights reserved.
// Use of this source code is governed by the license in the LICENSE file.

package boxcli
Expand All @@ -15,7 +15,8 @@ import (
)

type listCmdFlags struct {
config configFlags
config configFlags
outdated bool
}

func listCmd() *cobra.Command {
Expand All @@ -34,6 +35,10 @@ func listCmd() *cobra.Command {
return errors.WithStack(err)
}

if flags.outdated {
return printOutdatedPackages(cmd, box)
}

for _, pkg := range box.AllPackagesIncludingRemovedTriggerPackages() {
resolvedVersion, err := pkg.ResolvedVersion()
if err != nil {
Expand All @@ -57,6 +62,28 @@ func listCmd() *cobra.Command {
return nil
},
}

cmd.Flags().BoolVar(&flags.outdated, "outdated", false, "List outdated packages")
flags.config.register(cmd)
return cmd
}

// printOutdatedPackages prints a list of outdated packages.
func printOutdatedPackages(cmd *cobra.Command, box *devbox.Devbox) error {
results, err := box.Outdated(cmd.Context())
if err != nil {
return errors.WithStack(err)
}

if len(results) == 0 {
cmd.Println("Your packages are up to date!")
return nil
}

cmd.Println("The following packages can be updated:")
for pkg, version := range results {
cmd.Printf(" * %-30s %s -> %s\n", pkg, version.Current, version.Latest)
}

return nil
}
2 changes: 1 addition & 1 deletion internal/boxcli/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func searchCmd() *cobra.Command {
query := args[0]
name, version, isVersioned := searcher.ParseVersionedPackage(query)
if !isVersioned {
results, err := searcher.Client().Search(query)
results, err := searcher.Client().Search(cmd.Context(), query)
if err != nil {
return err
}
Expand Down
Loading