@@ -7,6 +7,7 @@ use crate::installable::Installable;
77use crate :: interface:: { DarwinArgs , DarwinRebuildArgs , DarwinReplArgs , DarwinSubcommand } ;
88use crate :: nixos:: toplevel_for;
99use crate :: update:: update;
10+ use crate :: util:: get_hostname;
1011use crate :: Result ;
1112
1213const SYSTEM_PROFILE : & str = "/nix/var/nix/profiles/system" ;
@@ -33,37 +34,6 @@ enum DarwinRebuildVariant {
3334 Build ,
3435}
3536
36- fn get_hostname ( hostname : Option < String > ) -> Result < String > {
37- match & hostname {
38- Some ( h) => Ok ( h. to_owned ( ) ) ,
39- None => {
40- #[ cfg( not( target_os = "macos" ) ) ]
41- {
42- Ok ( hostname:: get ( )
43- . context ( "Failed to get hostname" ) ?
44- . to_str ( )
45- . unwrap ( )
46- . to_string ( ) )
47- }
48- #[ cfg( target_os = "macos" ) ]
49- {
50- use system_configuration:: {
51- core_foundation:: { base:: TCFType , string:: CFString } ,
52- sys:: dynamic_store_copy_specific:: SCDynamicStoreCopyLocalHostName ,
53- } ;
54-
55- let ptr = unsafe { SCDynamicStoreCopyLocalHostName ( std:: ptr:: null ( ) ) } ;
56- if ptr. is_null ( ) {
57- bail ! ( "Failed to get hostname" ) ;
58- }
59- let name = unsafe { CFString :: wrap_under_get_rule ( ptr) } ;
60-
61- Ok ( name. to_string ( ) )
62- }
63- }
64- }
65- }
66-
6737impl DarwinRebuildArgs {
6838 fn rebuild ( self , variant : DarwinRebuildVariant ) -> Result < ( ) > {
6939 use DarwinRebuildVariant :: * ;
@@ -76,7 +46,7 @@ impl DarwinRebuildArgs {
7646 update ( & self . common . installable , self . update_args . update_input ) ?;
7747 }
7848
79- let hostname = get_hostname ( self . hostname ) ?;
49+ let hostname = self . hostname . ok_or ( ( ) ) . or_else ( | ( ) | get_hostname ( ) ) ?;
8050
8151 let out_path: Box < dyn crate :: util:: MaybeTempPath > = match self . common . out_link {
8252 Some ( ref p) => Box :: new ( p. clone ( ) ) ,
@@ -170,7 +140,7 @@ impl DarwinReplArgs {
170140 bail ! ( "Nix doesn't support nix store installables." ) ;
171141 }
172142
173- let hostname = get_hostname ( self . hostname ) ?;
143+ let hostname = self . hostname . ok_or ( ( ) ) . or_else ( | ( ) | get_hostname ( ) ) ?;
174144
175145 if let Installable :: Flake {
176146 ref mut attribute, ..
0 commit comments