Skip to content

Commit 50fc8d2

Browse files
add --no-install flag to devbox update (#2508)
## Summary As part of getting devbox working in renovate, we need to run devbox in renovate's base image (added here containerbase/base#3191). The problem is the way nix is installed (already in that image) it cannot actually install anything. This is because it's a quirky variant of a single user install where all the `/nix/*` paths are set to custom values. We can work around this by just having devbox update the lockfile but not actually install anything (which is also a speed win) - but this functionality doesn't seem to available in the devbox cli currently. This is a potential implementation adding what we need for renovate to upgrade devbox projects. Happy for you to do it another way. The approach we've taken seems like it's misusing the `mode` variable a little bit. ## How was it tested? Manually tested only; run locally on a macbook, plus in the container linked above. - add some packages that are older - upgrade them by manually editing devbox.json - run `devbox update --no-install` to update all packages in `devbox.lock` to latest within ranges `devbox.json` - in the container this failed with `cmd.path=/usr/local/bin/nix cmd.stderr="cannot connect to socket at '/tmp/containerbase/cache/nix/state/daemon-socket/socket': No such file or directory"` but with this change it works - run `devbox update nodejs --no-install` also works for a single package - changes to lockfile seem to be the same as `devbox update` without the flag, so behaviour of this flag shouldn't surprise anyone
1 parent 9ec8286 commit 50fc8d2

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

internal/boxcli/update.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type updateCmdFlags struct {
1717
config configFlags
1818
sync bool
1919
allProjects bool
20+
noInstall bool
2021
}
2122

2223
func updateCmd() *cobra.Command {
@@ -49,6 +50,12 @@ func updateCmd() *cobra.Command {
4950
false,
5051
"update all projects in the working directory, recursively.",
5152
)
53+
command.Flags().BoolVar(
54+
&flags.noInstall,
55+
"no-install",
56+
false,
57+
"update lockfile but don't install anything",
58+
)
5259
return command
5360
}
5461

@@ -75,7 +82,8 @@ func updateCmdFunc(cmd *cobra.Command, args []string, flags *updateCmdFlags) err
7582
}
7683

7784
return box.Update(cmd.Context(), devopt.UpdateOpts{
78-
Pkgs: args,
85+
Pkgs: args,
86+
NoInstall: flags.noInstall,
7987
})
8088
}
8189

internal/devbox/devopt/devboxopts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type AddOpts struct {
5858

5959
type UpdateOpts struct {
6060
Pkgs []string
61+
NoInstall bool
6162
IgnoreMissingPackages bool
6263
}
6364

internal/devbox/packages.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,9 @@ const (
281281
install installMode = "install"
282282
uninstall installMode = "uninstall"
283283
// update is both install new package version and uninstall old package version
284-
update installMode = "update"
285-
ensure installMode = "ensure"
284+
update installMode = "update"
285+
ensure installMode = "ensure"
286+
noInstall installMode = "noInstall"
286287
)
287288

288289
// ensureStateIsUpToDate ensures the Devbox project state is up to date.

internal/devbox/update.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ func (d *Devbox) Update(ctx context.Context, opts devopt.UpdateOpts) error {
6868
if err := d.updateStdenv(); err != nil {
6969
return err
7070
}
71-
if err := d.ensureStateIsUpToDate(ctx, update); err != nil {
71+
mode := update
72+
if opts.NoInstall {
73+
mode = noInstall
74+
}
75+
if err := d.ensureStateIsUpToDate(ctx, mode); err != nil {
7276
return err
7377
}
7478

0 commit comments

Comments
 (0)