@@ -13,6 +13,7 @@ use crate::installable::Installable;
1313use crate :: interface:: OsSubcommand :: { self } ;
1414use crate :: interface:: { self , OsGenerationsArgs , OsRebuildArgs , OsReplArgs } ;
1515use crate :: update:: update;
16+ use crate :: util:: ensure_ssh_key_login;
1617use crate :: util:: get_hostname;
1718
1819const SYSTEM_PROFILE : & str = "/nix/var/nix/profiles/system" ;
@@ -51,6 +52,11 @@ impl OsRebuildArgs {
5152 fn rebuild ( self , variant : OsRebuildVariant ) -> Result < ( ) > {
5253 use OsRebuildVariant :: * ;
5354
55+ if self . build_host . is_some ( ) || self . target_host . is_some ( ) {
56+ // if it fails its okay
57+ let _ = ensure_ssh_key_login ( ) ;
58+ }
59+
5460 let elevate = if self . bypass_root_check {
5561 warn ! ( "Bypassing root check, now running nix as root" ) ;
5662 false
@@ -102,6 +108,7 @@ impl OsRebuildArgs {
102108 . extra_arg ( "--out-link" )
103109 . extra_arg ( out_path. get_path ( ) )
104110 . extra_args ( & self . extra_args )
111+ . builder ( self . build_host . clone ( ) )
105112 . message ( "Building NixOS configuration" )
106113 . nom ( !self . common . no_nom )
107114 . run ( ) ?;
@@ -121,14 +128,18 @@ impl OsRebuildArgs {
121128 Some ( spec) => out_path. get_path ( ) . join ( "specialisation" ) . join ( spec) ,
122129 } ;
123130
131+ debug ! ( "exists: {}" , target_profile. exists( ) ) ;
132+
124133 target_profile. try_exists ( ) . context ( "Doesn't exist" ) ?;
125134
126- Command :: new ( "nvd" )
127- . arg ( "diff" )
128- . arg ( CURRENT_PROFILE )
129- . arg ( & target_profile)
130- . message ( "Comparing changes" )
131- . run ( ) ?;
135+ if self . build_host . is_none ( ) && self . target_host . is_none ( ) {
136+ Command :: new ( "nvd" )
137+ . arg ( "diff" )
138+ . arg ( CURRENT_PROFILE )
139+ . arg ( & target_profile)
140+ . message ( "Comparing changes" )
141+ . run ( ) ?;
142+ }
132143
133144 if self . common . dry || matches ! ( variant, Build ) {
134145 if self . common . ask {
@@ -146,14 +157,28 @@ impl OsRebuildArgs {
146157 }
147158 }
148159
160+ if let Some ( target_host) = & self . target_host {
161+ Command :: new ( "nix" )
162+ . args ( [
163+ "copy" ,
164+ "--to" ,
165+ format ! ( "ssh://{}" , target_host) . as_str ( ) ,
166+ target_profile. to_str ( ) . unwrap ( ) ,
167+ ] )
168+ . message ( "Copying configuration to target" )
169+ . run ( ) ?;
170+ } ;
171+
149172 if let Test | Switch = variant {
150173 // !! Use the target profile aka spec-namespaced
151174 let switch_to_configuration =
152175 target_profile. join ( "bin" ) . join ( "switch-to-configuration" ) ;
176+ let switch_to_configuration = switch_to_configuration. canonicalize ( ) . unwrap ( ) ;
153177 let switch_to_configuration = switch_to_configuration. to_str ( ) . unwrap ( ) ;
154178
155179 Command :: new ( switch_to_configuration)
156180 . arg ( "test" )
181+ . ssh ( self . target_host . clone ( ) )
157182 . message ( "Activating configuration" )
158183 . elevate ( elevate)
159184 . run ( ) ?;
@@ -163,17 +188,21 @@ impl OsRebuildArgs {
163188 Command :: new ( "nix" )
164189 . elevate ( elevate)
165190 . args ( [ "build" , "--no-link" , "--profile" , SYSTEM_PROFILE ] )
166- . arg ( out_path. get_path ( ) )
191+ . arg ( out_path. get_path ( ) . canonicalize ( ) . unwrap ( ) )
192+ . ssh ( self . target_host . clone ( ) )
167193 . run ( ) ?;
168194
169195 // !! Use the base profile aka no spec-namespace
170196 let switch_to_configuration = out_path
171197 . get_path ( )
172198 . join ( "bin" )
173199 . join ( "switch-to-configuration" ) ;
200+ let switch_to_configuration = switch_to_configuration. canonicalize ( ) . unwrap ( ) ;
201+ let switch_to_configuration = switch_to_configuration. to_str ( ) . unwrap ( ) ;
174202
175203 Command :: new ( switch_to_configuration)
176204 . arg ( "boot" )
205+ . ssh ( self . target_host . clone ( ) )
177206 . elevate ( elevate)
178207 . message ( "Adding configuration to bootloader" )
179208 . run ( ) ?;
0 commit comments