Skip to content

Commit 1cdda81

Browse files
committed
Merge branch 'main' of https://github.com/jetify-com/devbox into feature/json-plugin-schema
2 parents 8b613b4 + c0d4d98 commit 1cdda81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+796
-536
lines changed

docs/app/docs/devbox_examples/databases/mysql.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,16 @@ MYSQL_BASEDIR=.devbox/nix/profile/default
4646
MYSQL_HOME=./.devbox/virtenv/mysql/run
4747
MYSQL_DATADIR=./.devbox/virtenv/mysql/data
4848
MYSQL_UNIX_PORT=./.devbox/virtenv/mysql/run/mysql.sock
49-
MYSQL_PID_FILE=./.devbox/mysql/run/mysql.pid
49+
MYSQL_PID_FILE=./.devbox/virtenv/mysql/run/mysql.pid
50+
MYSQL_CONF=./devbox.d/mysql/my.cnf
5051
```
5152

5253
### Files
5354

55+
The following helper file will be created in your project directory:
56+
57+
* \{PROJECT_DIR\}/devbox.d/mysql/my.cnf
58+
5459
The plugin will also create the following helper files in your project's `.devbox/virtenv` folder:
5560

5661
* mysql/flake.nix

docs/app/docs/devbox_examples/languages/elixir.md

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,59 @@
22
title: Elixir
33
---
44

5-
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:
5+
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`.
66

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

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

1111
## Adding Elixir to your project
1212

13-
`devbox add elixir bash`, or add the following to your `devbox.json`
13+
`devbox add elixir`, or add the following to your `devbox.json`
1414

1515
```json
1616
"packages": [
17-
"elixir@latest",
18-
"bash@latest"
17+
"elixir@latest"
1918
],
2019
```
2120

22-
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)
21+
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)
2322

24-
## Installing Hex and Rebar locally
23+
## Elixir Plugin Support
2524

26-
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:
25+
Devbox will automatically use the following configuration when you install Elixir with `devbox add`.
26+
27+
### Environment Variables
28+
29+
`$MIX_HOME` and `$HEX_HOME` configure Mix/Hex to install artifacts locally, while `$ERL_AFLAGS` enables shell history in `iex`:
30+
31+
```bash
32+
MIX_HOME={PROJECT_DIR}/.devbox/virtenv/elixir/mix
33+
HEX_HOME={PROJECT_DIR}/.devbox/virtenv/elixir/hex
34+
ERL_AFLAGS="-kernel shell_history enabled"
35+
```
36+
37+
### Disabling the Elixir Plugin
38+
39+
You can disable the Elixir plugin by running `devbox add elixir --disable-plugin`, or by setting the `disable_plugin` field in your `devbox.json`:
2740

2841
```json
29-
"shell": {
30-
"init_hook": [
31-
"mkdir -p .nix-mix",
32-
"mkdir -p .nix-hex",
33-
"export MIX_HOME=$PWD/.nix-mix",
34-
"export HEX_HOME=$PWD/.nix-hex",
35-
"export ERL_AFLAGS='-kernel shell_history enabled'",
36-
"mix local.hex --force",
37-
"mix local.rebar --force"
38-
]
39-
}
42+
{
43+
"packages": {
44+
"elixir": {
45+
"version": "latest",
46+
"disable_plugin": true
47+
}
48+
},
49+
}
4050
```
4151

42-
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`.
52+
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.
53+
54+
If the plugin is disabled, it's recommended to manually set `$ERL_AFLAGS` to preserve `iex` shell history:
55+
56+
```json
57+
"env": {
58+
"ERL_AFLAGS": "-kernel shell_history enabled"
59+
}
60+
```

docs/app/docs/guides/plugins.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This doc describes how to use Devbox Plugins with your project. **Plugins** prov
88

99
### Built-in Plugins
1010

11-
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.
11+
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.
1212

1313
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:
1414

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

3839

3940
### Local Plugins

examples/development/elixir/elixir_hello/devbox.json

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
{
2-
"packages": {
3-
"elixir": "latest"
4-
},
5-
"env": {
6-
"MIX_HOME": "$PWD/.nix-mix",
7-
"HEX_HOME": "$PWD/.nix-hex",
8-
"ERL_AFLAGS": "-kernel shell_history enabled"
9-
},
2+
"packages": [
3+
"elixir@latest"
4+
],
105
"shell": {
116
"init_hook": [
12-
"mkdir -p .nix-mix",
13-
"mkdir -p .nix-hex",
14-
"mix local.hex --force",
15-
"mix local.rebar --force",
167
"mix deps.get"
178
],
189
"scripts": {

examples/development/elixir/elixir_hello/devbox.lock

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,51 @@
22
"lockfile_version": "1",
33
"packages": {
44
"elixir@latest": {
5-
"last_modified": "2024-02-10T18:15:24Z",
6-
"resolved": "github:NixOS/nixpkgs/10b813040df67c4039086db0f6eaf65c536886c6#elixir",
5+
"last_modified": "2024-11-28T07:51:56Z",
6+
"plugin_version": "0.0.1",
7+
"resolved": "github:NixOS/nixpkgs/226216574ada4c3ecefcbbec41f39ce4655f78ef#elixir",
78
"source": "devbox-search",
8-
"version": "1.15.7",
9+
"version": "1.17.3",
910
"systems": {
1011
"aarch64-darwin": {
1112
"outputs": [
1213
{
1314
"name": "out",
14-
"path": "/nix/store/kf294q6pwmqv8hb5ivis509y1wjjgm09-elixir-1.15.7",
15+
"path": "/nix/store/91w79z55qsjkhnbs3a21l3h27va98mf6-elixir-1.17.3",
1516
"default": true
1617
}
1718
],
18-
"store_path": "/nix/store/kf294q6pwmqv8hb5ivis509y1wjjgm09-elixir-1.15.7"
19+
"store_path": "/nix/store/91w79z55qsjkhnbs3a21l3h27va98mf6-elixir-1.17.3"
1920
},
2021
"aarch64-linux": {
2122
"outputs": [
2223
{
2324
"name": "out",
24-
"path": "/nix/store/f5x2w7df45vahjcpjf76dv101il8xq98-elixir-1.15.7",
25+
"path": "/nix/store/pz4hk0sp4zj76waaprlfdmvc4xdblz55-elixir-1.17.3",
2526
"default": true
2627
}
2728
],
28-
"store_path": "/nix/store/f5x2w7df45vahjcpjf76dv101il8xq98-elixir-1.15.7"
29+
"store_path": "/nix/store/pz4hk0sp4zj76waaprlfdmvc4xdblz55-elixir-1.17.3"
2930
},
3031
"x86_64-darwin": {
3132
"outputs": [
3233
{
3334
"name": "out",
34-
"path": "/nix/store/6vv8qlvhpi62nk5d06lhi5isvlg7bcj9-elixir-1.15.7",
35+
"path": "/nix/store/gnjg57wv71svvqw7s3rxyjc6lkps2r95-elixir-1.17.3",
3536
"default": true
3637
}
3738
],
38-
"store_path": "/nix/store/6vv8qlvhpi62nk5d06lhi5isvlg7bcj9-elixir-1.15.7"
39+
"store_path": "/nix/store/gnjg57wv71svvqw7s3rxyjc6lkps2r95-elixir-1.17.3"
3940
},
4041
"x86_64-linux": {
4142
"outputs": [
4243
{
4344
"name": "out",
44-
"path": "/nix/store/dlq14nswvq479pmnrwlyn2hyk6cwp65a-elixir-1.15.7",
45+
"path": "/nix/store/rx7qr8bar4qldx6yg3njvm8hn84d3yyk-elixir-1.17.3",
4546
"default": true
4647
}
4748
],
48-
"store_path": "/nix/store/dlq14nswvq479pmnrwlyn2hyk6cwp65a-elixir-1.15.7"
49+
"store_path": "/nix/store/rx7qr8bar4qldx6yg3njvm8hn84d3yyk-elixir-1.17.3"
4950
}
5051
}
5152
}

internal/devbox/devbox.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import (
4646
"go.jetpack.io/devbox/internal/shellgen"
4747
"go.jetpack.io/devbox/internal/telemetry"
4848
"go.jetpack.io/devbox/internal/ux"
49+
"go.jetpack.io/devbox/nix/flake"
4950
)
5051

5152
const (
@@ -202,8 +203,14 @@ func (d *Devbox) ConfigHash() (string, error) {
202203
return cachehash.Bytes(buf.Bytes()), nil
203204
}
204205

205-
func (d *Devbox) NixPkgsCommitHash() string {
206-
return d.cfg.NixPkgsCommitHash()
206+
func (d *Devbox) Stdenv() flake.Ref {
207+
return flake.Ref{
208+
Type: flake.TypeGitHub,
209+
Owner: "NixOS",
210+
Repo: "nixpkgs",
211+
Ref: "nixpkgs-unstable",
212+
Rev: d.cfg.NixPkgsCommitHash(),
213+
}
207214
}
208215

209216
func (d *Devbox) Generate(ctx context.Context) error {

internal/devbox/packages.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"go.jetpack.io/devbox/internal/setup"
2929
"go.jetpack.io/devbox/internal/shellgen"
3030
"go.jetpack.io/devbox/internal/telemetry"
31+
"go.jetpack.io/devbox/nix/flake"
3132
"go.jetpack.io/pkg/auth"
3233

3334
"go.jetpack.io/devbox/internal/boxcli/usererr"
@@ -101,10 +102,17 @@ func (d *Devbox) Add(ctx context.Context, pkgsNames []string, opts devopt.AddOpt
101102
// This means it didn't validate and we don't want to fallback to legacy
102103
// Just propagate the error.
103104
return err
104-
} else if _, err := nix.Search(d.lockfile.LegacyNixpkgsPath(pkg.Raw)); err != nil {
105-
// This means it looked like a devbox package or attribute path, but we
106-
// could not find it in search or in the legacy nixpkgs path.
107-
return usererr.New("Package %s not found", pkg.Raw)
105+
} else {
106+
installable := flake.Installable{
107+
Ref: d.lockfile.Stdenv(),
108+
AttrPath: pkg.Raw,
109+
}
110+
_, err := nix.Search(installable.String())
111+
if err != nil {
112+
// This means it looked like a devbox package or attribute path, but we
113+
// could not find it in search or in the legacy nixpkgs path.
114+
return usererr.New("Package %s not found", pkg.Raw)
115+
}
108116
}
109117

110118
ux.Finfof(d.stderr, "Adding package %q to devbox.json\n", packageNameForConfig)

internal/devbox/update.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ func (d *Devbox) Update(ctx context.Context, opts devopt.UpdateOpts) error {
6565
}
6666
}
6767

68+
if err := d.updateStdenv(); err != nil {
69+
return err
70+
}
6871
if err := d.ensureStateIsUpToDate(ctx, update); err != nil {
6972
return err
7073
}
@@ -103,6 +106,15 @@ func (d *Devbox) inputsToUpdate(
103106
return pkgsToUpdate, nil
104107
}
105108

109+
func (d *Devbox) updateStdenv() error {
110+
err := d.lockfile.Remove(d.Stdenv().String())
111+
if err != nil {
112+
return err
113+
}
114+
d.lockfile.Stdenv() // will re-resolve the stdenv flake
115+
return nil
116+
}
117+
106118
func (d *Devbox) updateDevboxPackage(pkg *devpkg.Package) error {
107119
resolved, err := d.lockfile.FetchResolvedPackage(pkg.Raw)
108120
if err != nil {

internal/devconfig/configfile/file.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,8 @@ func (c *ConfigFile) Equals(other *ConfigFile) bool {
9595
}
9696

9797
func (c *ConfigFile) NixPkgsCommitHash() string {
98-
// The commit hash for nixpkgs-unstable on 2023-10-25 from status.nixos.org
99-
const DefaultNixpkgsCommit = "75a52265bda7fd25e06e3a67dee3f0354e73243c"
100-
101-
if c == nil || c.Nixpkgs == nil || c.Nixpkgs.Commit == "" {
102-
return DefaultNixpkgsCommit
98+
if c == nil || c.Nixpkgs == nil {
99+
return ""
103100
}
104101
return c.Nixpkgs.Commit
105102
}

internal/devpkg/package.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,13 @@ func newPackage(raw string, isInstallable func() bool, locker lock.Locker) *Pack
151151
return pkg
152152
}
153153

154-
// We currently don't lock flake references in devbox.lock, so there's
155-
// nothing to resolve.
156-
pkg.resolve = sync.OnceValue(func() error { return nil })
154+
pkg.resolve = sync.OnceValue(func() error {
155+
// Don't lock flakes that are local paths.
156+
if parsed.Ref.Type == flake.TypePath {
157+
return nil
158+
}
159+
return resolve(pkg)
160+
})
157161
pkg.setInstallable(parsed, locker.ProjectDir())
158162
pkg.outputs = outputs{selectedNames: strings.Split(parsed.Outputs, ",")}
159163
pkg.Patch = pkgNeedsPatch(pkg.CanonicalName(), configfile.PatchAuto)

0 commit comments

Comments
 (0)