Skip to content

Commit 3df27b9

Browse files
committed
Merge 0.13.6 into latest
1 parent aab705d commit 3df27b9

File tree

25 files changed

+651
-96
lines changed

25 files changed

+651
-96
lines changed

.github/workflows/debug.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
default: "ubuntu-latest"
1010
type: choice
1111
options:
12-
- macos-12
12+
- macos-latest
1313
- ubuntu-latest
1414

1515
permissions:

docs/app/docs/cli_reference/devbox_completion_zsh.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22

33
Generate the autocompletion script for the zsh shell.
44

5-
If shell completion is not already enabled in your environment you will need
6-
to enable it. You can execute the following once:
5+
If you are using Oh My Zsh, just run the following:
6+
7+
```bash
8+
mkdir -p ~/.oh-my-zsh/completions
9+
devbox completion zsh > ~/.oh-my-zsh/completions/_devbox
10+
```
11+
12+
If you are not using Oh My Zsh and shell completion is not already enabled in your environment you will need
13+
to enable it. You can execute the following once:
714

815
```bash
916
echo "autoload -U compinit; compinit" >> ~/.zshrc

docs/app/docs/configuration.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@ Currently, you can only set values using string literals, `$PWD`, and `$PATH`. A
182182

183183
### Env From
184184

185-
Env from takes a string or list of strings for loading environment variables into your shells and scripts. Currently it supports loading from two sources: .env files, and Jetify Secrsts.
185+
Env from takes a string for loading environment variables into your shells and scripts. Currently it supports loading from two sources: .env files, and Jetify Secrets.
186186

187187
#### .env Files
188188

189-
You can load environment variables from a `.env` file by adding the path to the file in the `env_from` field. This is useful for loading secrets or other sensitive information that you don't want to store in your `devbox.json`.
189+
You can load environment variables from a `.env` file by adding the path to the file in the `env_from` field (the file must end with `.env`). This is useful for loading secrets or other sensitive information that you don't want to store in your `devbox.json`.
190190

191191
```json
192192
{
@@ -198,15 +198,15 @@ This will load the environment variables from the `.env` file into your shell wh
198198

199199
#### Jetify Secrets
200200

201-
You can securely load secrets from Jetify Secrets by running `devbox secrets init` and creating a project in Jetify Cloud. This will add the `jetpack-cloud` field to `env_from` in your project.
201+
You can securely load secrets from Jetify Secrets by running `devbox secrets init` and creating a project in Jetify Cloud. This will add the `jetify-cloud` field to `env_from` in your project.
202202

203203
```json
204204
{
205-
"env_from": "jetpack-cloud"
205+
"env_from": "jetify-cloud"
206206
}
207207
```
208208

209-
Note that setting secrets securetly with Jetify Secrets requires a Jetify Cloud account. For more information, see the [Jetify Secrets](/docs/cloud/secrets/) guide.
209+
Note that setting secrets securely with Jetify Secrets requires a Jetify Cloud account. For more information, see the [Jetify Secrets](/docs/cloud/secrets/) guide.
210210

211211
### Shell
212212

docs/app/docs/guides/creating_plugins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ The plugin.json below installs MongoDB + the Mongo shell, and sets the environme
219219
"version": "0.0.1",
220220
"description": "Plugin for the [`mongodb`](https://www.nixhub.io/packages/mongodb) package. This plugin configures MonogoDB to use a local config file and data directory for this project, and configures a mongodb service.",
221221
"packages": [
222-
"mongodb@latest"
222+
"mongodb@latest",
223223
"mongosh@latest"
224224
],
225225
"env": {

docs/app/docs/guides/secrets.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ For environment variables that you want to keep out of your `devbox.json` file,
2828
{
2929
"packages": {},
3030
"shell": {},
31-
"env_from": [
32-
"path/to/.env"
33-
]
31+
"env_from": "path/to/.env"
3432
}
3533
```
3634

docs/app/docs/quickstart.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Follow the instruction from [the installation guide](./installing_devbox.mdx).
2121
:::note
2222
If you want to try Devbox before installing it, you can open a cloud shell on your browser using the link below
2323

24-
[![Open In Devspace](https://www.jetify.com/img/devbox/open-in-devbox.svg)](https://www.jetify.com/devbox/templates/tutorial)
24+
[![Open In Devspace](https://www.jetify.com/img/devbox/open-in-devspace.svg)](https://www.jetify.com/devbox/templates/tutorial)
2525
:::
2626

2727
## Create a Development Environment

docs/app/docusaurus.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const config = {
6666
routeBasePath: "cloud",
6767
sidebarPath: require.resolve("./cloud_sidebars.js"),
6868
},
69-
],[
69+
], [
7070
"@docusaurus/plugin-content-docs",
7171
{
7272
id: "nixhub",

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
let
1212
pkgs = nixpkgs.legacyPackages.${system};
1313

14-
lastTag = "0.13.5";
14+
lastTag = "0.13.6";
1515

1616
revision =
1717
if (self ? shortRev)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ require (
4242
github.com/zealic/go2node v0.1.0
4343
go.jetify.com/typeid v1.2.0
4444
go.jetpack.io/envsec v0.0.16-0.20240604163020-540ad12af899
45-
go.jetpack.io/pkg v0.0.0-20240815004735-7649b4283d51
45+
go.jetpack.io/pkg v0.0.0-20241025195518-152e59e26d5d
4646
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8
4747
golang.org/x/mod v0.18.0
4848
golang.org/x/oauth2 v0.21.0

go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/build/build.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
package build
55

66
import (
7+
"fmt"
8+
"log/slog"
79
"os"
10+
"path/filepath"
811
"runtime"
912
"strconv"
1013
"sync"
@@ -98,3 +101,33 @@ func DashboardHostname() string {
98101
}
99102
return "https://cloud.jetify.com"
100103
}
104+
105+
// SourceDir searches for the source code directory that built the current
106+
// binary.
107+
func SourceDir() (string, error) {
108+
_, file, _, ok := runtime.Caller(0)
109+
if !ok || file == "" {
110+
return "", fmt.Errorf("build.SourceDir: binary is missing path info")
111+
}
112+
slog.Debug("trying to determine path to devbox source using runtime.Caller", "path", file)
113+
114+
dir := filepath.Dir(file)
115+
if _, err := os.Stat(dir); err != nil {
116+
if filepath.IsAbs(file) {
117+
return "", fmt.Errorf("build.SourceDir: path to binary source doesn't exist: %v", err)
118+
}
119+
return "", fmt.Errorf("build.SourceDir: binary was built with -trimpath")
120+
}
121+
122+
for {
123+
_, err := os.Stat(filepath.Join(dir, "go.mod"))
124+
if err == nil {
125+
slog.Debug("found devbox source directory", "path", dir)
126+
return dir, nil
127+
}
128+
if dir == "/" || dir == "." {
129+
return "", fmt.Errorf("build.SourceDir: can't find go.mod in any parent directories of %s", file)
130+
}
131+
dir = filepath.Dir(dir)
132+
}
133+
}

internal/devbox/devbox.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"go.jetpack.io/devbox/internal/devbox/envpath"
3333
"go.jetpack.io/devbox/internal/devbox/generate"
3434
"go.jetpack.io/devbox/internal/devconfig"
35+
"go.jetpack.io/devbox/internal/devconfig/configfile"
3536
"go.jetpack.io/devbox/internal/devpkg"
3637
"go.jetpack.io/devbox/internal/devpkg/pkgtype"
3738
"go.jetpack.io/devbox/internal/envir"
@@ -373,7 +374,7 @@ func (d *Devbox) EnvExports(ctx context.Context, opts devopt.EnvExportsOpts) (st
373374
envStr := exportify(envs)
374375

375376
if opts.RunHooks {
376-
hooksStr := ". " + shellgen.ScriptPath(d.ProjectDir(), shellgen.HooksFilename)
377+
hooksStr := ". \"" + shellgen.ScriptPath(d.ProjectDir(), shellgen.HooksFilename) + "\""
377378
envStr = fmt.Sprintf("%s\n%s;\n", envStr, hooksStr)
378379
}
379380

@@ -1009,9 +1010,9 @@ func (d *Devbox) configEnvs(
10091010
}
10101011
} else if d.cfg.Root.EnvFrom != "" {
10111012
return nil, usererr.New(
1012-
"unknown from_env value: %s. Supported value is: %q.",
1013+
"unknown env_from value: %s. Supported values are: \"%q\" or a path to a file ending in \".env\"",
10131014
d.cfg.Root.EnvFrom,
1014-
"jetpack-cloud",
1015+
configfile.JetifyCloudEnvFromValue,
10151016
)
10161017
}
10171018
for k, v := range d.cfg.Env() {

internal/devconfig/configfile/env.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import (
88
"github.com/hashicorp/go-envparse"
99
)
1010

11+
var JetifyCloudEnvFromValue = "jetify-cloud"
12+
1113
func (c *ConfigFile) IsEnvsecEnabled() bool {
1214
// envsec for legacy. jetpack-cloud for legacy
13-
return c.EnvFrom == "envsec" || c.EnvFrom == "jetpack-cloud" || c.EnvFrom == "jetify-cloud"
15+
return c.EnvFrom == "envsec" || c.EnvFrom == "jetpack-cloud" || c.EnvFrom == JetifyCloudEnvFromValue
1416
}
1517

1618
func (c *ConfigFile) IsdotEnvEnabled() bool {
@@ -25,10 +27,13 @@ func (c *ConfigFile) ParseEnvsFromDotEnv() (map[string]string, error) {
2527
if !c.IsdotEnvEnabled() {
2628
return nil, fmt.Errorf("env file does not have a .env extension")
2729
}
28-
29-
file, err := os.Open(c.EnvFrom)
30+
envFileAbsPath := c.EnvFrom
31+
if !filepath.IsAbs(c.EnvFrom) {
32+
envFileAbsPath = filepath.Join(filepath.Dir(c.AbsRootPath), c.EnvFrom)
33+
}
34+
file, err := os.Open(envFileAbsPath)
3035
if err != nil {
31-
return nil, fmt.Errorf("failed to open file: %s", c.EnvFrom)
36+
return nil, fmt.Errorf("failed to open file: %s", envFileAbsPath)
3237
}
3338
defer file.Close()
3439

internal/shellgen/flake_plan.go

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"slices"
1111
"strings"
1212

13+
"go.jetpack.io/devbox/internal/build"
1314
"go.jetpack.io/devbox/internal/devpkg"
1415
"go.jetpack.io/devbox/internal/nix"
1516
"go.jetpack.io/devbox/internal/patchpkg"
@@ -73,9 +74,11 @@ func (f *flakePlan) needsGlibcPatch() bool {
7374
}
7475

7576
type glibcPatchFlake struct {
76-
// DevboxExecutable is the absolute path to the Devbox binary to use as
77-
// the flake's builder. It must not be the wrapper script.
78-
DevboxExecutable string
77+
// DevboxFlake provides the devbox binary that will act as the patch
78+
// flake's builder. By default it's set to "github:jetify-com/devbox/" +
79+
// [build.Version]. For dev builds, it's set to the local path to the
80+
// Devbox source code (this Go module) if it's available.
81+
DevboxFlake flake.Ref
7982

8083
// NixpkgsGlibcFlakeRef is a flake reference to the nixpkgs flake
8184
// containing the new glibc package.
@@ -100,43 +103,57 @@ type glibcPatchFlake struct {
100103
}
101104

102105
func newGlibcPatchFlake(nixpkgsGlibcRev string, packages []*devpkg.Package) (glibcPatchFlake, error) {
103-
// Get the path to the actual devbox binary (not the /usr/bin/devbox
104-
// wrapper) so the flake build can use it.
105-
exe, err := os.Executable()
106-
if err != nil {
107-
return glibcPatchFlake{}, err
108-
}
109-
exe, err = filepath.EvalSymlinks(exe)
110-
if err != nil {
111-
return glibcPatchFlake{}, err
106+
patchFlake := glibcPatchFlake{
107+
DevboxFlake: flake.Ref{
108+
Type: flake.TypeGitHub,
109+
Owner: "jetify-com",
110+
Repo: "devbox",
111+
Ref: build.Version,
112+
},
113+
NixpkgsGlibcFlakeRef: "flake:nixpkgs/" + nixpkgsGlibcRev,
112114
}
113115

114-
flake := glibcPatchFlake{
115-
DevboxExecutable: exe,
116-
NixpkgsGlibcFlakeRef: "flake:nixpkgs/" + nixpkgsGlibcRev,
116+
// In dev builds, use the local Devbox flake for patching packages
117+
// instead of the one on GitHub. Using build.IsDev doesn't work because
118+
// DEVBOX_PROD=1 will attempt to download 0.0.0-dev from GitHub.
119+
if strings.HasPrefix(build.Version, "0.0.0") {
120+
src, err := build.SourceDir()
121+
if err != nil {
122+
slog.Error("can't find the local devbox flake for patching, falling back to the latest github release", "err", err)
123+
patchFlake.DevboxFlake = flake.Ref{
124+
Type: flake.TypeGitHub,
125+
Owner: "jetify-com",
126+
Repo: "devbox",
127+
}
128+
} else {
129+
patchFlake.DevboxFlake = flake.Ref{Type: flake.TypePath, Path: src}
130+
}
117131
}
132+
118133
for _, pkg := range packages {
119134
// Check to see if this is a CUDA package. If so, we need to add
120135
// it to the flake dependencies so that we can patch other
121136
// packages to reference it (like Python).
122-
relAttrPath, err := flake.systemRelativeAttrPath(pkg)
137+
relAttrPath, err := patchFlake.systemRelativeAttrPath(pkg)
123138
if err != nil {
124139
return glibcPatchFlake{}, err
125140
}
126141
if strings.HasPrefix(relAttrPath, "cudaPackages") {
127-
if err := flake.addDependency(pkg); err != nil {
142+
if err := patchFlake.addDependency(pkg); err != nil {
128143
return glibcPatchFlake{}, err
129144
}
130145
}
131146

132147
if !pkg.Patch {
133148
continue
134149
}
135-
if err := flake.addOutput(pkg); err != nil {
150+
if err := patchFlake.addOutput(pkg); err != nil {
136151
return glibcPatchFlake{}, err
137152
}
138153
}
139-
return flake, nil
154+
155+
slog.Debug("creating new patch flake", "flake", &patchFlake)
156+
return patchFlake, nil
140157
}
141158

142159
// addInput adds a flake input that provides pkg.
@@ -301,5 +318,34 @@ func (g *glibcPatchFlake) writeTo(dir string) error {
301318
slog.Debug("error copying system libcuda.so to flake", "dir", dir)
302319
}
303320
}
304-
return writeFromTemplate(dir, g, "glibc-patch.nix", "flake.nix")
321+
changed, err := writeFromTemplate(dir, g, "glibc-patch.nix", "flake.nix")
322+
if err != nil {
323+
return err
324+
}
325+
if changed {
326+
_ = os.Remove(filepath.Join(dir, "flake.lock"))
327+
}
328+
return nil
329+
}
330+
331+
func (g *glibcPatchFlake) LogValue() slog.Value {
332+
inputs := make([]slog.Attr, 0, 2+len(g.Inputs))
333+
inputs = append(inputs,
334+
slog.String("devbox", g.DevboxFlake.String()),
335+
slog.String("nixpkgs-glibc", g.NixpkgsGlibcFlakeRef),
336+
)
337+
for k, v := range g.Inputs {
338+
inputs = append(inputs, slog.String(k, v))
339+
}
340+
341+
var outputs []string
342+
for _, pkg := range g.Outputs.Packages {
343+
for attrPath := range pkg {
344+
outputs = append(outputs, attrPath)
345+
}
346+
}
347+
return slog.GroupValue(
348+
slog.Attr{Key: "inputs", Value: slog.GroupValue(inputs...)},
349+
slog.Attr{Key: "outputs", Value: slog.AnyValue(outputs)},
350+
)
305351
}

0 commit comments

Comments
 (0)