Skip to content

Commit 10d7390

Browse files
authored
[install UX] show incremental progress (#491)
## Summary I was playing around with making the install step show more incremental progress. This PR explores it by doing `nix-env --install` for just the nixpkgs and then each package individually. This lets us print installation output as we go along. The implementation is rather hacky. I override `devbox.cfg.Packages` to re-generate the `development.nix`. There's more likely a more direct `nix-env --install` command invocation we can use but I was failing to figure it out this evening. I don't think we should commit this code as-is, but sharing for product oriented feedback and suggestions on the right `nix-env --install` command to use so we can improve the hacky code. ## How was it tested? deployed a custom binary to a custom VM: ``` Devbox Cloud Remote development environments powered by Nix ✓ File syncing started → Connecting to virtual machine Installing nix packages. This may take a while... Ensure nixpkgs is downloaded, extracted and evaluated. Ensure package installed: go_1_19 Ensure package installed: bazel Done. Starting a devbox shell... (devbox ☁️ ) testdata/go/go-1.19 via 🐹 💫 watching for changes ```
1 parent e9a9a4f commit 10d7390

File tree

2 files changed

+65
-21
lines changed

2 files changed

+65
-21
lines changed

examples/testdata/go/go-1.19/devbox.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
}
1010
},
1111
"nixpkgs": {
12-
"commit": "af9e00071d0971eb292fd5abef334e66eda3cb69"
12+
"commit": "52e3e80afff4b16ccb7c52e9f0f5220552f03d04"
1313
}
1414
}

internal/impl/devbox.go

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"go.jetpack.io/devbox/internal/planner/plansdk"
3030
"go.jetpack.io/devbox/internal/plugin"
3131
"go.jetpack.io/devbox/internal/telemetry"
32+
"go.jetpack.io/devbox/internal/ux/stepper"
3233
"golang.org/x/exp/slices"
3334
)
3435

@@ -587,14 +588,14 @@ func (d *Devbox) ensurePackagesAreInstalled(mode installMode) error {
587588
if mode == uninstall {
588589
installingVerb = "Uninstalling"
589590
}
590-
_, _ = fmt.Fprintf(d.writer, "%s nix packages. This may take a while... ", installingVerb)
591+
_, _ = fmt.Fprintf(d.writer, "%s nix packages. This may take a while...\n", installingVerb)
591592

592593
// We need to re-install the packages
593594
if err := d.installNixProfile(); err != nil {
594595
fmt.Fprintln(d.writer)
595596
return errors.Wrap(err, "apply Nix derivation")
596597
}
597-
fmt.Fprintln(d.writer, "done.")
598+
fmt.Fprintln(d.writer, "Done.")
598599

599600
return plugin.RemoveInvalidSymlinks(d.projectDir)
600601
}
@@ -667,30 +668,73 @@ func (d *Devbox) installNixProfile() (err error) {
667668
_ = d.copyFlakeLockToDevboxLock()
668669
}
669670
}()
670-
} else {
671-
cmd = exec.Command(
672-
"nix-env",
673-
"--profile", profileDir,
674-
"--install",
675-
"-f", filepath.Join(d.projectDir, ".devbox/gen/development.nix"),
676-
)
677-
}
678671

679-
cmd.Env = nix.DefaultEnv()
672+
cmd.Env = nix.DefaultEnv()
680673

681-
debug.Log("Running command: %s\n", cmd.Args)
682-
_, err = cmd.Output()
674+
debug.Log("Running command: %s\n", cmd.Args)
675+
_, err = cmd.Output()
676+
677+
var exitErr *exec.ExitError
678+
if errors.As(err, &exitErr) {
679+
return errors.Errorf("running command %s: exit status %d with command stderr: %s",
680+
cmd, exitErr.ExitCode(), string(exitErr.Stderr))
681+
}
682+
if err != nil {
683+
return errors.Errorf("running command %s: %v", cmd, err)
684+
}
683685

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))
686+
return nil
688687
}
689-
if err != nil {
690-
return errors.Errorf("running command %s: %v", cmd, err)
688+
689+
// Non flakes below:
690+
691+
// Append an empty string to warm the nixpkgs cache
692+
packages := append([]string{""}, d.cfg.Packages...)
693+
694+
total := len(packages)
695+
for idx, pkg := range packages {
696+
stepNum := idx + 1
697+
698+
var msg string
699+
if pkg == "" {
700+
msg = fmt.Sprintf("[%d/%d] nixpkgs", stepNum, total)
701+
} else {
702+
msg = fmt.Sprintf("[%d/%d] %s", stepNum, total, pkg)
703+
}
704+
705+
step := stepper.Start(msg)
706+
707+
// TODO savil. hook this up to gcurtis's mirrorURL
708+
nixPkgsURL := fmt.Sprintf("https://github.com/nixos/nixpkgs/archive/%s.tar.gz", d.cfg.Nixpkgs.Commit)
709+
710+
var cmd *exec.Cmd
711+
if pkg != "" {
712+
cmd = exec.Command(
713+
"nix-env",
714+
"--profile", profileDir,
715+
"-f", nixPkgsURL,
716+
"--install",
717+
"--attr", pkg,
718+
)
719+
} else {
720+
cmd = exec.Command(
721+
"nix-instantiate",
722+
"--eval",
723+
"--attr", "path",
724+
nixPkgsURL,
725+
)
726+
}
727+
728+
cmd.Env = nix.DefaultEnv()
729+
_, err = cmd.Output()
730+
if err != nil {
731+
step.Fail(msg)
732+
return errors.Errorf("error running command %s: %v", cmd, err)
733+
}
734+
step.Success(msg)
691735
}
692736

693-
return
737+
return nil
694738
}
695739

696740
// writeScriptsToFiles writes scripts defined in devbox.json into files inside .devbox/gen/scripts.

0 commit comments

Comments
 (0)