Skip to content

Commit b0d6032

Browse files
authored
[UX] Show add (nix build) stdout (#1826)
1 parent 37de8f0 commit b0d6032

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

internal/devbox/packages.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,8 @@ func (d *Devbox) installNixPackagesToStore(ctx context.Context) error {
443443
args := &nix.BuildArgs{
444444
AllowInsecure: pkg.HasAllowInsecure(),
445445
// --no-link to avoid generating the result objects
446-
Flags: []string{"--no-link"},
446+
Flags: []string{"--no-link"},
447+
Writer: d.stderr,
447448
}
448449
err = nix.Build(ctx, args, installable)
449450
if err != nil {

internal/nix/build.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ package nix
22

33
import (
44
"context"
5-
"fmt"
5+
"io"
66
"os"
7-
"os/exec"
87

9-
"github.com/pkg/errors"
108
"go.jetpack.io/devbox/internal/debug"
119
)
1210

1311
type BuildArgs struct {
1412
AllowInsecure bool
1513
Flags []string
14+
Writer io.Writer
1615
}
1716

1817
func Build(ctx context.Context, args *BuildArgs, installables ...string) error {
@@ -26,14 +25,13 @@ func Build(ctx context.Context, args *BuildArgs, installables ...string) error {
2625
cmd.Env = allowInsecureEnv(cmd.Env)
2726
}
2827

28+
// If nix build runs as tty, the output is much nicer. If we ever
29+
// need to change this to our own writers, consider that you may need
30+
// to implement your own nicer output. --print-build-logs flag may be useful.
31+
cmd.Stdin = os.Stdin
32+
cmd.Stdout = args.Writer
33+
cmd.Stderr = args.Writer
34+
2935
debug.Log("Running cmd: %s\n", cmd)
30-
_, err := cmd.Output()
31-
if err != nil {
32-
if exitErr := (&exec.ExitError{}); errors.As(err, &exitErr) {
33-
debug.Log("Nix build exit code: %d, output: %s\n", exitErr.ExitCode(), exitErr.Stderr)
34-
return fmt.Errorf("nix build exit code: %d, output: %s, err: %w", exitErr.ExitCode(), exitErr.Stderr, err)
35-
}
36-
return err
37-
}
38-
return nil
36+
return cmd.Run()
3937
}

0 commit comments

Comments
 (0)