@@ -330,9 +330,14 @@ impl OsRebuildArgs {
330
330
. canonicalize ( )
331
331
. context ( "Failed to resolve output path" ) ?;
332
332
333
+ let system_profile_path = self . profile . as_ref ( ) . map_or_else (
334
+ || std:: ffi:: OsStr :: new ( SYSTEM_PROFILE ) ,
335
+ |p| p. as_os_str ( ) ,
336
+ ) ;
333
337
Command :: new ( "nix" )
334
338
. elevate ( elevate. then_some ( elevation. clone ( ) ) )
335
- . args ( [ "build" , "--no-link" , "--profile" , SYSTEM_PROFILE ] )
339
+ . args ( [ "build" , "--no-link" , "--profile" ] )
340
+ . arg ( system_profile_path)
336
341
. arg ( & canonical_out_path)
337
342
. ssh ( self . target_host . clone ( ) )
338
343
. with_required_env ( )
@@ -401,7 +406,11 @@ impl OsRollbackArgs {
401
406
info ! ( "Rolling back to generation {}" , target_generation. number) ;
402
407
403
408
// Construct path to the generation
404
- let profile_dir = Path :: new ( SYSTEM_PROFILE ) . parent ( ) . unwrap_or_else ( || {
409
+ let system_profile_path = self
410
+ . profile
411
+ . as_deref ( )
412
+ . unwrap_or_else ( || Path :: new ( SYSTEM_PROFILE ) ) ;
413
+ let profile_dir = system_profile_path. parent ( ) . unwrap_or_else ( || {
405
414
tracing:: warn!(
406
415
"SYSTEM_PROFILE has no parent, defaulting to /nix/var/nix/profiles"
407
416
) ;
@@ -469,10 +478,14 @@ impl OsRollbackArgs {
469
478
info ! ( "Setting system profile..." ) ;
470
479
471
480
// Instead of direct symlink operations, use a command with proper elevation
481
+ let system_profile_path = self
482
+ . profile
483
+ . as_deref ( )
484
+ . unwrap_or_else ( || Path :: new ( SYSTEM_PROFILE ) ) ;
472
485
Command :: new ( "ln" )
473
486
. arg ( "-sfn" ) // force, symbolic link
474
487
. arg ( & generation_link)
475
- . arg ( SYSTEM_PROFILE )
488
+ . arg ( system_profile_path )
476
489
. elevate ( elevate. then_some ( elevation. clone ( ) ) )
477
490
. message ( "Setting system profile" )
478
491
. with_required_env ( )
@@ -534,10 +547,14 @@ impl OsRollbackArgs {
534
547
let current_gen_link =
535
548
profile_dir. join ( format ! ( "system-{current_gen_number}-link" ) ) ;
536
549
550
+ let system_profile_path = self
551
+ . profile
552
+ . as_deref ( )
553
+ . unwrap_or_else ( || Path :: new ( SYSTEM_PROFILE ) ) ;
537
554
Command :: new ( "ln" )
538
555
. arg ( "-sfn" ) // Force, symbolic link
539
556
. arg ( & current_gen_link)
540
- . arg ( SYSTEM_PROFILE )
557
+ . arg ( system_profile_path )
541
558
. elevate ( elevate. then_some ( elevation) )
542
559
. message ( "Rolling back system profile" )
543
560
. with_required_env ( )
0 commit comments