@@ -107,7 +107,6 @@ impl Devenv {
107
107
. expect ( "Failed to create DEVENV_HOME directory" ) ;
108
108
std:: fs:: create_dir_all ( & devenv_home_gc)
109
109
. expect ( "Failed to create DEVENV_HOME_GC directory" ) ;
110
- std:: fs:: create_dir_all ( & devenv_dot_gc) . expect ( "Failed to create .devenv/gc directory" ) ;
111
110
112
111
let nix = cnix:: Nix :: new (
113
112
options. config . clone ( ) ,
@@ -119,7 +118,7 @@ impl Devenv {
119
118
devenv_root. clone ( ) ,
120
119
)
121
120
. await
122
- . unwrap ( ) ; // TODO: handle error
121
+ . expect ( "Failed to initialize Nix" ) ;
123
122
124
123
Self {
125
124
config : options. config ,
@@ -175,16 +174,14 @@ impl Devenv {
175
174
file. write_all ( path. contents ( ) )
176
175
} )
177
176
. expect ( "Failed to append to existing file" ) ;
178
- } else {
179
- if target_path. exists ( ) && !EXISTING_REQUIRED_FILES . contains ( & filename) {
180
- if let Some ( utf8_contents) = path. contents_utf8 ( ) {
181
- confirm_overwrite ( & target_path, utf8_contents. to_string ( ) ) ?;
182
- } else {
183
- bail ! ( "Failed to read file contents as UTF-8" ) ;
184
- }
177
+ } else if target_path. exists ( ) && !EXISTING_REQUIRED_FILES . contains ( & filename) {
178
+ if let Some ( utf8_contents) = path. contents_utf8 ( ) {
179
+ confirm_overwrite ( & target_path, utf8_contents. to_string ( ) ) ?;
185
180
} else {
186
- std :: fs :: write ( & target_path , path . contents ( ) ) . expect ( "Failed to write file" ) ;
181
+ bail ! ( "Failed to read file contents as UTF-8 " ) ;
187
182
}
183
+ } else {
184
+ std:: fs:: write ( & target_path, path. contents ( ) ) . expect ( "Failed to write file" ) ;
188
185
}
189
186
}
190
187
@@ -238,7 +235,7 @@ impl Devenv {
238
235
cmd : & Option < String > ,
239
236
args : & [ String ] ,
240
237
) -> Result < Vec < String > > {
241
- self . assemble ( false ) ?;
238
+ self . assemble ( false ) . await ?;
242
239
let env = self . get_dev_environment ( false ) . await ?;
243
240
244
241
let mut develop_args = vec ! [
@@ -286,7 +283,7 @@ impl Devenv {
286
283
}
287
284
288
285
pub async fn update ( & mut self , input_name : & Option < String > ) -> Result < ( ) > {
289
- self . assemble ( false ) ?;
286
+ self . assemble ( false ) . await ?;
290
287
291
288
let msg = match input_name {
292
289
Some ( input_name) => format ! ( "Updating devenv.lock with input {input_name}" ) ,
@@ -310,7 +307,7 @@ impl Devenv {
310
307
) ;
311
308
312
309
async move {
313
- self . assemble ( false ) ?;
310
+ self . assemble ( false ) . await ?;
314
311
315
312
let container_store_path = self
316
313
. nix
@@ -410,8 +407,8 @@ impl Devenv {
410
407
. await
411
408
}
412
409
413
- pub fn repl ( & mut self ) -> Result < ( ) > {
414
- self . assemble ( false ) ?;
410
+ pub async fn repl ( & mut self ) -> Result < ( ) > {
411
+ self . assemble ( false ) . await ?;
415
412
self . nix . repl ( )
416
413
}
417
414
@@ -460,7 +457,7 @@ impl Devenv {
460
457
}
461
458
462
459
pub async fn search ( & mut self , name : & str ) -> Result < ( ) > {
463
- self . assemble ( false ) ?;
460
+ self . assemble ( false ) . await ?;
464
461
465
462
let build_options = cnix:: Options {
466
463
logging : false ,
@@ -531,7 +528,7 @@ impl Devenv {
531
528
}
532
529
533
530
pub async fn tasks_run ( & mut self , roots : Vec < String > ) -> Result < ( ) > {
534
- self . assemble ( false ) ?;
531
+ self . assemble ( false ) . await ?;
535
532
if roots. is_empty ( ) {
536
533
bail ! ( "No tasks specified." ) ;
537
534
}
@@ -569,7 +566,7 @@ impl Devenv {
569
566
}
570
567
571
568
pub async fn test ( & mut self ) -> Result < ( ) > {
572
- self . assemble ( true ) ?;
569
+ self . assemble ( true ) . await ?;
573
570
574
571
// collect tests
575
572
let test_script = {
@@ -617,14 +614,14 @@ impl Devenv {
617
614
}
618
615
619
616
pub async fn info ( & mut self ) -> Result < ( ) > {
620
- self . assemble ( false ) ?;
617
+ self . assemble ( false ) . await ?;
621
618
let output = self . nix . metadata ( ) . await ?;
622
619
println ! ( "{}" , output) ;
623
620
Ok ( ( ) )
624
621
}
625
622
626
623
pub async fn build ( & mut self , attributes : & [ String ] ) -> Result < ( ) > {
627
- self . assemble ( false ) ?;
624
+ self . assemble ( false ) . await ?;
628
625
let attributes: Vec < String > = if attributes. is_empty ( ) {
629
626
// construct dotted names of all attributes that we need to build
630
627
let build_output = self . nix . eval ( & [ "build" ] ) . await ?;
@@ -671,7 +668,7 @@ impl Devenv {
671
668
detach : & bool ,
672
669
log_to_file : & bool ,
673
670
) -> Result < ( ) > {
674
- self . assemble ( false ) ?;
671
+ self . assemble ( false ) . await ?;
675
672
if !self . has_processes ( ) . await ? {
676
673
error ! ( "No 'processes' option defined: https://devenv.sh/processes/" ) ;
677
674
bail ! ( "No processes defined" ) ;
@@ -791,7 +788,7 @@ impl Devenv {
791
788
Ok ( ( ) )
792
789
}
793
790
794
- pub fn assemble ( & mut self , is_testing : bool ) -> Result < ( ) > {
791
+ pub async fn assemble ( & mut self , is_testing : bool ) -> Result < ( ) > {
795
792
if self . assembled {
796
793
return Ok ( ( ) ) ;
797
794
}
@@ -803,9 +800,13 @@ impl Devenv {
803
800
$ devenv init
804
801
" } ) ;
805
802
}
803
+
806
804
fs:: create_dir_all ( & self . devenv_dot_gc )
807
805
. unwrap_or_else ( |_| panic ! ( "Failed to create {}" , self . devenv_dot_gc. display( ) ) ) ;
808
806
807
+ // Initialise any Nix state
808
+ self . nix . assemble ( ) . await ?;
809
+
809
810
let mut flake_inputs = HashMap :: new ( ) ;
810
811
for ( input, attrs) in self . config . inputs . iter ( ) {
811
812
match config:: FlakeInput :: try_from ( attrs) {
@@ -878,7 +879,7 @@ impl Devenv {
878
879
}
879
880
880
881
pub async fn get_dev_environment ( & mut self , json : bool ) -> Result < DevEnv > {
881
- self . assemble ( false ) ?;
882
+ self . assemble ( false ) . await ?;
882
883
883
884
let gc_root = self . devenv_dot_gc . join ( "shell" ) ;
884
885
let span = tracing:: info_span!( "building_shell" , devenv. user_message = "Building shell" , ) ;
0 commit comments