Skip to content

Commit

Permalink
add --no-install flag to devbox update (#2508)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
jay-aye-see-kay authored Feb 12, 2025
1 parent 9ec8286 commit 50fc8d2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
10 changes: 9 additions & 1 deletion internal/boxcli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type updateCmdFlags struct {
config configFlags
sync bool
allProjects bool
noInstall bool
}

func updateCmd() *cobra.Command {
Expand Down Expand Up @@ -49,6 +50,12 @@ func updateCmd() *cobra.Command {
false,
"update all projects in the working directory, recursively.",
)
command.Flags().BoolVar(
&flags.noInstall,
"no-install",
false,
"update lockfile but don't install anything",
)
return command
}

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

return box.Update(cmd.Context(), devopt.UpdateOpts{
Pkgs: args,
Pkgs: args,
NoInstall: flags.noInstall,
})
}

Expand Down
1 change: 1 addition & 0 deletions internal/devbox/devopt/devboxopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type AddOpts struct {

type UpdateOpts struct {
Pkgs []string
NoInstall bool
IgnoreMissingPackages bool
}

Expand Down
5 changes: 3 additions & 2 deletions internal/devbox/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ const (
install installMode = "install"
uninstall installMode = "uninstall"
// update is both install new package version and uninstall old package version
update installMode = "update"
ensure installMode = "ensure"
update installMode = "update"
ensure installMode = "ensure"
noInstall installMode = "noInstall"
)

// ensureStateIsUpToDate ensures the Devbox project state is up to date.
Expand Down
6 changes: 5 additions & 1 deletion internal/devbox/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ func (d *Devbox) Update(ctx context.Context, opts devopt.UpdateOpts) error {
if err := d.updateStdenv(); err != nil {
return err
}
if err := d.ensureStateIsUpToDate(ctx, update); err != nil {
mode := update
if opts.NoInstall {
mode = noInstall
}
if err := d.ensureStateIsUpToDate(ctx, mode); err != nil {
return err
}

Expand Down

0 comments on commit 50fc8d2

Please sign in to comment.