From 50fc8d28cfdad9d67317a044904b52174f8ab935 Mon Sep 17 00:00:00 2001 From: Jack Rose Date: Wed, 12 Feb 2025 11:31:10 +1100 Subject: [PATCH] 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 https://github.com/containerbase/base/pull/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 --- internal/boxcli/update.go | 10 +++++++++- internal/devbox/devopt/devboxopts.go | 1 + internal/devbox/packages.go | 5 +++-- internal/devbox/update.go | 6 +++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/internal/boxcli/update.go b/internal/boxcli/update.go index 009cb1b362d..eb2428092a0 100644 --- a/internal/boxcli/update.go +++ b/internal/boxcli/update.go @@ -17,6 +17,7 @@ type updateCmdFlags struct { config configFlags sync bool allProjects bool + noInstall bool } func updateCmd() *cobra.Command { @@ -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 } @@ -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, }) } diff --git a/internal/devbox/devopt/devboxopts.go b/internal/devbox/devopt/devboxopts.go index 43f6224df53..b59759fe567 100644 --- a/internal/devbox/devopt/devboxopts.go +++ b/internal/devbox/devopt/devboxopts.go @@ -58,6 +58,7 @@ type AddOpts struct { type UpdateOpts struct { Pkgs []string + NoInstall bool IgnoreMissingPackages bool } diff --git a/internal/devbox/packages.go b/internal/devbox/packages.go index d7ca3cc236d..c5a1b5af95d 100644 --- a/internal/devbox/packages.go +++ b/internal/devbox/packages.go @@ -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. diff --git a/internal/devbox/update.go b/internal/devbox/update.go index 79b4693c3ab..4a06c8e2a9b 100644 --- a/internal/devbox/update.go +++ b/internal/devbox/update.go @@ -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 }