@@ -249,7 +249,7 @@ const (
249
249
// 1. Skipping certain operations that may not apply.
250
250
// 2. User messaging to explain what operations are happening, because this function may take time to execute.
251
251
//
252
- // nolint :revive to turn off linter complaining about function complexity
252
+ // linter :revive is turned off due to complaining about function complexity
253
253
func (d * Devbox ) ensureStateIsUpToDate (ctx context.Context , mode installMode ) error { //nolint:revive
254
254
defer trace .StartRegion (ctx , "devboxEnsureStateIsUpToDate" ).End ()
255
255
defer debug .FunctionTimer ().End ()
@@ -259,10 +259,7 @@ func (d *Devbox) ensureStateIsUpToDate(ctx context.Context, mode installMode) er
259
259
// then we skip some operations below for speed.
260
260
// Remove the local.lock file so that we re-compute the project state when
261
261
// we are in the devbox environment again.
262
- fmt .Printf ("mode is not ensure and env is not enabled, so will remove local.lock on exit\n " )
263
-
264
262
defer func () { _ = d .lockfile .RemoveLocal () }()
265
- // return nil
266
263
}
267
264
268
265
// if mode is install or uninstall, then we need to update the nix-profile
@@ -275,12 +272,10 @@ func (d *Devbox) ensureStateIsUpToDate(ctx context.Context, mode installMode) er
275
272
if mode == ensure {
276
273
// if mode is ensure and we are up to date, then we can skip the rest
277
274
if upToDate {
278
- fmt .Printf ("state is up to date. Returning early\n " )
279
275
return nil
280
276
}
281
277
fmt .Fprintln (d .stderr , "Ensuring packages are installed." )
282
278
}
283
- fmt .Printf ("state is not up to date. Continuing...\n " )
284
279
285
280
// Validate packages. Must be run up-front and definitely prior to computeEnv
286
281
// and syncNixProfile below that will evaluate the flake and may give
@@ -300,9 +295,6 @@ func (d *Devbox) ensureStateIsUpToDate(ctx context.Context, mode installMode) er
300
295
return err
301
296
}
302
297
303
- fmt .Printf ("mode is %s\n " , mode )
304
- fmt .Printf ("env is enabled: %v\n " , d .IsEnvEnabled ())
305
-
306
298
if err := shellgen .GenerateForPrintEnv (ctx , d ); err != nil {
307
299
return err
308
300
}
@@ -341,7 +333,6 @@ func (d *Devbox) ensureStateIsUpToDate(ctx context.Context, mode installMode) er
341
333
}
342
334
}
343
335
344
- fmt .Printf ("calling lockfile.tidy\n " )
345
336
// Ensure we clean out packages that are no longer needed.
346
337
d .lockfile .Tidy ()
347
338
@@ -428,72 +419,46 @@ func (d *Devbox) InstallRunXPackages(ctx context.Context) error {
428
419
429
420
// installNixPackagesToStore will install all the packages in the nix store, if
430
421
// mode is install or update, and we're not in a devbox environment.
431
- // This is done by running `nix build` on the flake
422
+ // This is done by running `nix build` on the flake. We do this so that the
423
+ // packages will be available in the nix store when computing the devbox environment
424
+ // and installing in the nix profile (even if offline).
432
425
func (d * Devbox ) installNixPackagesToStore (ctx context.Context ) error {
433
- packages , err := d .AllInstallablePackages ( )
426
+ packages , err := d .packagesToInstallInProfile ( ctx )
434
427
if err != nil {
435
428
return err
436
429
}
437
- packages = lo .Filter (packages , devpkg .IsNix ) // Remove non-nix packages from the list
438
430
431
+ names := []string {}
439
432
installables := []string {}
440
433
for _ , pkg := range packages {
441
434
i , err := pkg .Installable ()
442
435
if err != nil {
443
436
return err
444
437
}
445
438
installables = append (installables , i )
439
+ names = append (names , pkg .String ())
446
440
}
447
441
448
442
if len (installables ) == 0 {
449
443
return nil
450
444
}
451
445
446
+ ux .Finfo (d .stderr , "Installing to the nix store: %s. This may take a brief while.\n " , strings .Join (names , " " ))
447
+
452
448
// --no-link to avoid generating the result objects
453
449
return nix .Build (ctx , []string {"--no-link" }, installables ... )
454
450
}
455
451
456
452
// validatePackagesToBeInstalled will ensure that packages are available to be installed
457
453
// in the user's current system.
458
454
func (d * Devbox ) validatePackagesToBeInstalled (ctx context.Context ) error {
459
- // First, fetch the profile items from the nix-profile,
460
- profileDir , err := d .profilePath ()
461
- if err != nil {
462
- return err
463
- }
464
- profileItems , err := nixprofile .ProfileListItems (ctx , d .stderr , profileDir )
455
+ // First, get the packages to install
456
+ packagesToInstall , err := d .packagesToInstallInProfile (ctx )
465
457
if err != nil {
466
458
return err
467
459
}
468
460
469
- // Second, get and prepare all the packages that must be installed in this project
470
- packages , err := d .AllInstallablePackages ()
471
- if err != nil {
472
- return err
473
- }
474
- packages = lo .Filter (packages , devpkg .IsNix ) // Remove non-nix packages from the list
475
- if err := devpkg .FillNarInfoCache (ctx , packages ... ); err != nil {
476
- return err
477
- }
478
-
479
- // Third, compute which packages need to be installed
480
- packagesToInstall := []* devpkg.Package {}
481
- // Note: because devpkg.Package uses memoization when normalizing attribute paths (slow operation),
482
- // and since we're reusing the Package objects, this O(n*m) loop becomes O(n+m) wrt the slow operation.
483
- for _ , pkg := range packages {
484
- found := false
485
- for _ , item := range profileItems {
486
- if item .Matches (pkg , d .lockfile ) {
487
- found = true
488
- break
489
- }
490
- }
491
- if ! found {
492
- packagesToInstall = append (packagesToInstall , pkg )
493
- }
494
- }
495
-
496
- // Last, validate that packages that need to be installed are in fact installable
461
+ // Then, validate that packages that need to be installed are in fact installable
497
462
// on the user's current system.
498
463
for _ , pkg := range packagesToInstall {
499
464
inCache , err := pkg .IsInBinaryCache ()
@@ -524,3 +489,43 @@ func (d *Devbox) validatePackagesToBeInstalled(ctx context.Context) error {
524
489
}
525
490
return nil
526
491
}
492
+
493
+ func (d * Devbox ) packagesToInstallInProfile (ctx context.Context ) ([]* devpkg.Package , error ) {
494
+ // First, fetch the profile items from the nix-profile,
495
+ profileDir , err := d .profilePath ()
496
+ if err != nil {
497
+ return nil , err
498
+ }
499
+ profileItems , err := nixprofile .ProfileListItems (ctx , d .stderr , profileDir )
500
+ if err != nil {
501
+ return nil , err
502
+ }
503
+
504
+ // Second, get and prepare all the packages that must be installed in this project
505
+ packages , err := d .AllInstallablePackages ()
506
+ if err != nil {
507
+ return nil , err
508
+ }
509
+ packages = lo .Filter (packages , devpkg .IsNix ) // Remove non-nix packages from the list
510
+ if err := devpkg .FillNarInfoCache (ctx , packages ... ); err != nil {
511
+ return nil , err
512
+ }
513
+
514
+ // Third, compute which packages need to be installed
515
+ packagesToInstall := []* devpkg.Package {}
516
+ // Note: because devpkg.Package uses memoization when normalizing attribute paths (slow operation),
517
+ // and since we're reusing the Package objects, this O(n*m) loop becomes O(n+m) wrt the slow operation.
518
+ for _ , pkg := range packages {
519
+ found := false
520
+ for _ , item := range profileItems {
521
+ if item .Matches (pkg , d .lockfile ) {
522
+ found = true
523
+ break
524
+ }
525
+ }
526
+ if ! found {
527
+ packagesToInstall = append (packagesToInstall , pkg )
528
+ }
529
+ }
530
+ return packagesToInstall , nil
531
+ }
0 commit comments