Skip to content

Commit fb18b8e

Browse files
authored
[install UX] go back to using development.nix (#512)
## Summary With the recent install-UX improvement of #491, we may run into issues for existing users. #508 summarizes the issue and has a workaround fix implemented. However, it had me thinking whether this is introducing more risk than we want for this week. To summarize, the improvements made in #491 and later in #506 are: 1. #491: use stepper. Install each package individually, instead of using `development.nix`. 2. #506: stream the output of `nix-env --install`. This PR makes it so we continue doing #506 to preserve some UX improvement, but revert #491 to minimize risk. When I try it in `devbox cloud shell` with `bazel` and `buf`, the streaming output helps preserve the feeling of progress being made. The viewer is no longer left pondering "is it stuck? is it broken?". ## How was it tested? - built a linux devbox binary and deployed a custom VM - did `devbox cloud shell` to that VM: The following output shows but is printed in a streaming fashion as opposed to blank for a long time and then shows up in one-go. ``` Devbox Cloud Remote development environments powered by Nix ✓ File syncing started → Connecting to virtual machine Installing nix packages. This may take a while... installing 'devbox-development' these 2 derivations will be built: /nix/store/9yk55y5ywvm4ihnllfa2kcz158bmbfbg-builder.pl.drv /nix/store/xwcvqhd7fd49dndn5wvn2hx2vcxlrkp0-devbox-development.drv these 59 paths will be fetched (919.80 MiB download, 1815.57 MiB unpacked): /nix/store/039g378vc3pc3dvi9dzdlrd0i4q93qwf-binutils-2.39 /nix/store/0zmylwn0sznzflf137hhqlnnyskr6cdk-openjdk-headless-11.0.15+10 /nix/store/1d6ian3r8kdzspw8hacjhl3xkp40g1lj-binutils-wrapper-2.39 /nix/store/1dgws25664p544znpc6f1nh9xmjf4ykc-pcre-8.45 /nix/store/1gf2flfqnpqbr1b4p4qz2f72y42bs56r-gcc-11.3.0 /nix/store/1i5ah27gxx3a3fyjyydfwwzqq8ni33i8-ncurses-6.3-p20220507 ... // omitted /nix/store/y6aj732zm9m87c82fpvf103a1xb22blp-file-5.43 /nix/store/zdba9frlxj2ba8ca095win3nphsiiqhb-python3-3.10.8 /nix/store/zlcnmqq14jz5x9439jf937mvayyl63da-xz-5.2.7-bin copying path '/nix/store/hlqzdmnprp3cqwmj4zpzllb8aarjkbvb-iana-etc-20220915' from 'https://cache.nixos.org'... copying path '/nix/store/2js892db4aspqb06b9hlxmcr0g97gf3z-bazel-deps' from 'https://cache.nixos.org'... copying path '/nix/store/039g378vc3pc3dvi9dzdlrd0i4q93qwf-binutils-2.39' from 'https://cache.nixos.org'... copying path '/nix/store/a8mhcagrsly7c7mpjrpsnaahk4aax056-bzip2-1.0.8-bin' from 'https://cache.nixos.org'... copying path '/nix/store/xwl6y60ffijfbhxb754dlxk3pkjgw0d2-ed-1.18' from 'https://cache.nixos.org'... copying path '/nix/store/a1ad8qiqqb9fpg5a9rhlkm44s02sr61p-expand-response-params' from 'https://cache.nixos.org'... ... // omitted ```
1 parent 52dada3 commit fb18b8e

File tree

1 file changed

+18
-103
lines changed

1 file changed

+18
-103
lines changed

internal/impl/devbox.go

Lines changed: 18 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package impl
66

77
import (
8-
"bufio"
98
"fmt"
109
"io"
1110
"os"
@@ -30,7 +29,6 @@ import (
3029
"go.jetpack.io/devbox/internal/planner/plansdk"
3130
"go.jetpack.io/devbox/internal/plugin"
3231
"go.jetpack.io/devbox/internal/telemetry"
33-
"go.jetpack.io/devbox/internal/ux/stepper"
3432
"golang.org/x/exp/slices"
3533
)
3634

@@ -669,111 +667,28 @@ func (d *Devbox) installNixProfile() (err error) {
669667
_ = d.copyFlakeLockToDevboxLock()
670668
}
671669
}()
672-
673-
cmd.Env = nix.DefaultEnv()
674-
675-
debug.Log("Running command: %s\n", cmd.Args)
676-
_, err = cmd.Output()
677-
678-
var exitErr *exec.ExitError
679-
if errors.As(err, &exitErr) {
680-
return errors.Errorf("running command %s: exit status %d with command stderr: %s",
681-
cmd, exitErr.ExitCode(), string(exitErr.Stderr))
682-
}
683-
if err != nil {
684-
return errors.Errorf("running command %s: %v", cmd, err)
685-
}
686-
687-
return nil
670+
} else { // Non flakes:
671+
cmd = exec.Command(
672+
"nix-env",
673+
"--profile", profileDir,
674+
"--install",
675+
"-f", filepath.Join(d.projectDir, ".devbox/gen/development.nix"),
676+
)
688677
}
689678

690-
// Non flakes below:
691-
692-
// Append an empty string to warm the nixpkgs cache
693-
packages := append([]string{""}, d.cfg.Packages...)
694-
695-
total := len(packages)
696-
for idx, pkg := range packages {
697-
stepNum := idx + 1
698-
699-
var msg string
700-
if pkg == "" {
701-
msg = fmt.Sprintf("[%d/%d] nixpkgs", stepNum, total)
702-
} else {
703-
msg = fmt.Sprintf("[%d/%d] %s", stepNum, total, pkg)
704-
}
705-
706-
step := stepper.Start(d.writer, msg)
707-
708-
// TODO savil. hook this up to gcurtis's mirrorURL
709-
nixPkgsURL := fmt.Sprintf("https://github.com/nixos/nixpkgs/archive/%s.tar.gz", d.cfg.Nixpkgs.Commit)
710-
711-
var cmd *exec.Cmd
712-
if pkg != "" {
713-
cmd = exec.Command(
714-
"nix-env",
715-
"--profile", profileDir,
716-
"-f", nixPkgsURL,
717-
"--install",
718-
"--attr", pkg,
719-
)
720-
} else {
721-
cmd = exec.Command(
722-
"nix-instantiate",
723-
"--eval",
724-
"--attr", "path",
725-
nixPkgsURL,
726-
)
727-
}
728-
729-
cmd.Env = nix.DefaultEnv()
679+
cmd.Env = nix.DefaultEnv()
680+
cmd.Stdout = d.writer
681+
cmd.Stderr = d.writer
682+
err = cmd.Run()
730683

731-
// Get a pipe to read from standard out
732-
pipe, err := cmd.StdoutPipe()
733-
if err != nil {
734-
return errors.New("unable to open stdout pipe")
735-
}
736-
737-
// Use the same writer for standard error
738-
cmd.Stderr = cmd.Stdout
739-
740-
// Make a new channel which will be used to ensure we get all output
741-
done := make(chan struct{})
742-
743-
// Create a scanner which scans pipe in a line-by-line fashion
744-
scanner := bufio.NewScanner(pipe)
745-
746-
// Use the scanner to scan the output line by line and log it
747-
// It's running in a goroutine so that it doesn't block
748-
go func() {
749-
750-
// Read line by line and process it
751-
for scanner.Scan() {
752-
line := scanner.Text()
753-
step.Display(fmt.Sprintf("%s %s", msg, line))
754-
}
755-
756-
// We're all done, unblock the channel
757-
done <- struct{}{}
758-
}()
759-
760-
// Start the command and check for errors
761-
if err := cmd.Start(); err != nil {
762-
step.Fail(msg)
763-
return errors.Errorf("error starting command %s: %v", cmd, err)
764-
}
765-
766-
// Wait for all output to be processed
767-
<-done
768-
769-
// Wait for the command to finish
770-
if err = cmd.Wait(); err != nil {
771-
step.Fail(msg)
772-
return errors.Errorf("error running command %s: %v", cmd, err)
773-
}
774-
step.Success(msg)
684+
var exitErr *exec.ExitError
685+
if errors.As(err, &exitErr) {
686+
return errors.Errorf("running command %s: exit status %d with command stderr: %s",
687+
cmd, exitErr.ExitCode(), string(exitErr.Stderr))
688+
}
689+
if err != nil {
690+
return errors.Errorf("running command %s: %v", cmd, err)
775691
}
776-
777692
return nil
778693
}
779694

0 commit comments

Comments
 (0)