Remove removes the `pkgs` from the config (i.e. devbox.json) and nix profile for this devbox project
(ctx context.Context, pkgs ...string)
| 239 | // Remove removes the `pkgs` from the config (i.e. devbox.json) and nix profile |
| 240 | // for this devbox project |
| 241 | func (d *Devbox) Remove(ctx context.Context, pkgs ...string) error { |
| 242 | ctx, task := trace.NewTask(ctx, "devboxRemove") |
| 243 | defer task.End() |
| 244 | |
| 245 | packagesToUninstall := []string{} |
| 246 | missingPkgs := []string{} |
| 247 | for _, pkg := range lo.Uniq(pkgs) { |
| 248 | found, _ := d.findPackageByName(pkg) |
| 249 | if found != nil { |
| 250 | packagesToUninstall = append(packagesToUninstall, found.Raw) |
| 251 | d.cfg.PackageMutator().Remove(found.Raw) |
| 252 | } else { |
| 253 | missingPkgs = append(missingPkgs, pkg) |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | if len(missingPkgs) > 0 { |
| 258 | ux.Fwarningf( |
| 259 | d.stderr, |
| 260 | "the following packages were not found in your devbox.json: %s\n", |
| 261 | strings.Join(missingPkgs, ", "), |
| 262 | ) |
| 263 | } |
| 264 | |
| 265 | if err := plugin.Remove(d.projectDir, packagesToUninstall); err != nil { |
| 266 | return err |
| 267 | } |
| 268 | |
| 269 | // this will clean up the now-extra package from nix profile and the lockfile |
| 270 | if err := d.ensureStateIsUpToDate(ctx, uninstall); err != nil { |
| 271 | return err |
| 272 | } |
| 273 | |
| 274 | return d.saveCfg() |
| 275 | } |
| 276 | |
| 277 | // installMode is an enum for helping with ensureStateIsUpToDate implementation |
| 278 | type installMode string |
no test coverage detected