@@ -121,6 +121,13 @@ impl OsArgs {
121
121
let is_flake = args. uses_flakes ( ) ;
122
122
Box :: new ( OsReplFeatures { is_flake } )
123
123
}
124
+ OsSubcommand :: Edit ( args) => {
125
+ if args. uses_flakes ( ) {
126
+ Box :: new ( FlakeFeatures )
127
+ } else {
128
+ Box :: new ( LegacyFeatures )
129
+ }
130
+ }
124
131
OsSubcommand :: Switch ( args)
125
132
| OsSubcommand :: Boot ( args)
126
133
| OsSubcommand :: Test ( args)
@@ -160,6 +167,9 @@ pub enum OsSubcommand {
160
167
/// Load system in a repl
161
168
Repl ( OsReplArgs ) ,
162
169
170
+ /// Edit NixOS configuration
171
+ Edit ( OsEditArgs ) ,
172
+
163
173
/// List available generations from profile path
164
174
Info ( OsGenerationsArgs ) ,
165
175
@@ -316,7 +326,29 @@ impl OsReplArgs {
316
326
#[ must_use]
317
327
pub fn uses_flakes ( & self ) -> bool {
318
328
// Check environment variables first
319
- if env:: var ( "NH_OS_FLAKE" ) . is_ok ( ) {
329
+ if env:: var ( "NH_OS_FLAKE" ) . is_ok_and ( |v| !v. is_empty ( ) ) {
330
+ return true ;
331
+ }
332
+
333
+ // Check installable type
334
+ matches ! ( self . installable, Installable :: Flake { .. } )
335
+ }
336
+ }
337
+
338
+ #[ derive( Debug , Args ) ]
339
+ pub struct OsEditArgs {
340
+ #[ command( flatten) ]
341
+ pub installable : Installable ,
342
+
343
+ /// When using a flake installable, select this hostname from nixosConfigurations
344
+ #[ arg( long, short = 'H' , global = true ) ]
345
+ pub hostname : Option < String > ,
346
+ }
347
+
348
+ impl OsEditArgs {
349
+ pub fn uses_flakes ( & self ) -> bool {
350
+ // Check environment variables first
351
+ if env:: var ( "NH_OS_FLAKE" ) . is_ok_and ( |v| !v. is_empty ( ) ) {
320
352
return true ;
321
353
}
322
354
@@ -447,6 +479,13 @@ impl HomeArgs {
447
479
let is_flake = args. uses_flakes ( ) ;
448
480
Box :: new ( HomeReplFeatures { is_flake } )
449
481
}
482
+ HomeSubcommand :: Edit ( args) => {
483
+ if args. uses_flakes ( ) {
484
+ Box :: new ( FlakeFeatures )
485
+ } else {
486
+ Box :: new ( LegacyFeatures )
487
+ }
488
+ }
450
489
HomeSubcommand :: Switch ( args) | HomeSubcommand :: Build ( args) => {
451
490
if args. uses_flakes ( ) {
452
491
Box :: new ( FlakeFeatures )
@@ -468,6 +507,9 @@ pub enum HomeSubcommand {
468
507
469
508
/// Load a home-manager configuration in a Nix REPL
470
509
Repl ( HomeReplArgs ) ,
510
+
511
+ /// Edit home-manager configuration
512
+ Edit ( HomeEditArgs ) ,
471
513
}
472
514
473
515
#[ derive( Debug , Args ) ]
@@ -543,6 +585,34 @@ impl HomeReplArgs {
543
585
}
544
586
}
545
587
588
+ #[ derive( Debug , Args ) ]
589
+ pub struct HomeEditArgs {
590
+ #[ command( flatten) ]
591
+ pub installable : Installable ,
592
+
593
+ /// Name of the flake homeConfigurations attribute, like username@hostname
594
+ ///
595
+ /// If unspecified, will try <username>@<hostname> and <username>
596
+ #[ arg( long, short) ]
597
+ pub configuration : Option < String > ,
598
+
599
+ /// Extra arguments passed to nix repl
600
+ #[ arg( last = true ) ]
601
+ pub extra_args : Vec < String > ,
602
+ }
603
+
604
+ impl HomeEditArgs {
605
+ pub fn uses_flakes ( & self ) -> bool {
606
+ // Check environment variables first
607
+ if env:: var ( "NH_HOME_FLAKE" ) . is_ok_and ( |v| !v. is_empty ( ) ) {
608
+ return true ;
609
+ }
610
+
611
+ // Check installable type
612
+ matches ! ( self . installable, Installable :: Flake { .. } )
613
+ }
614
+ }
615
+
546
616
#[ derive( Debug , Parser ) ]
547
617
/// Generate shell completion files into stdout
548
618
pub struct CompletionArgs {
@@ -567,6 +637,13 @@ impl DarwinArgs {
567
637
let is_flake = args. uses_flakes ( ) ;
568
638
Box :: new ( DarwinReplFeatures { is_flake } )
569
639
}
640
+ DarwinSubcommand :: Edit ( args) => {
641
+ if args. uses_flakes ( ) {
642
+ Box :: new ( FlakeFeatures )
643
+ } else {
644
+ Box :: new ( LegacyFeatures )
645
+ }
646
+ }
570
647
DarwinSubcommand :: Switch ( args) | DarwinSubcommand :: Build ( args) => {
571
648
if args. uses_flakes ( ) {
572
649
Box :: new ( FlakeFeatures )
@@ -586,6 +663,8 @@ pub enum DarwinSubcommand {
586
663
Build ( DarwinRebuildArgs ) ,
587
664
/// Load a nix-darwin configuration in a Nix REPL
588
665
Repl ( DarwinReplArgs ) ,
666
+ /// Edit nix-darwin configuration
667
+ Edit ( DarwinEditArgs ) ,
589
668
}
590
669
591
670
#[ derive( Debug , Args ) ]
@@ -645,6 +724,28 @@ impl DarwinReplArgs {
645
724
}
646
725
}
647
726
727
+ #[ derive( Debug , Args ) ]
728
+ pub struct DarwinEditArgs {
729
+ #[ command( flatten) ]
730
+ pub installable : Installable ,
731
+
732
+ /// When using a flake installable, select this hostname from darwinConfigurations
733
+ #[ arg( long, short = 'H' , global = true ) ]
734
+ pub hostname : Option < String > ,
735
+ }
736
+
737
+ impl DarwinEditArgs {
738
+ pub fn uses_flakes ( & self ) -> bool {
739
+ // Check environment variables first
740
+ if env:: var ( "NH_DARWIN_FLAKE" ) . is_ok_and ( |v| !v. is_empty ( ) ) {
741
+ return true ;
742
+ }
743
+
744
+ // Check installable type
745
+ matches ! ( self . installable, Installable :: Flake { .. } )
746
+ }
747
+ }
748
+
648
749
#[ derive( Debug , Args ) ]
649
750
pub struct UpdateArgs {
650
751
#[ arg( short = 'u' , long = "update" , conflicts_with = "update_input" ) ]
0 commit comments