@@ -95,6 +95,7 @@ pub enum OS {
95
95
MacOS {
96
96
/// Using nix-darwin
97
97
nix_darwin : bool ,
98
+ /// Architecture
98
99
arch : MacOSArch ,
99
100
} ,
100
101
/// On NixOS
@@ -103,19 +104,26 @@ pub enum OS {
103
104
Other ( os_info:: Type ) ,
104
105
}
105
106
107
+ /// macOS CPU architecture
106
108
#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
107
109
pub enum MacOSArch {
110
+ /// Apple Silicon
108
111
Arm64 ( AppleEmulation ) ,
112
+ /// Other architecture
109
113
Other ( Option < String > ) ,
110
114
}
111
115
116
+ /// Apple emulation mode
112
117
#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
113
118
pub enum AppleEmulation {
119
+ /// Not running on Apple Silicon
114
120
None ,
121
+ /// Running under Rosetta
115
122
Rosetta ,
116
123
}
117
124
118
125
impl AppleEmulation {
126
+ /// Detect Apple emulation mode for current process
119
127
pub fn new ( ) -> Self {
120
128
use is_proc_translated:: is_proc_translated;
121
129
if is_proc_translated ( ) {
@@ -133,6 +141,7 @@ impl Default for AppleEmulation {
133
141
}
134
142
135
143
impl MacOSArch {
144
+ /// Create a [MacOSArch] from an OS architecture string
136
145
pub fn from ( os_arch : Option < & str > ) -> MacOSArch {
137
146
match os_arch {
138
147
Some ( "arm64" ) => MacOSArch :: Arm64 ( AppleEmulation :: new ( ) ) ,
@@ -162,6 +171,7 @@ impl Display for OS {
162
171
}
163
172
164
173
impl OS {
174
+ /// Detect the OS
165
175
pub async fn detect ( ) -> Self {
166
176
let os_info = tokio:: task:: spawn_blocking ( os_info:: get) . await . unwrap ( ) ;
167
177
let os_type = os_info. os_type ( ) ;
@@ -221,6 +231,7 @@ impl Display for NixInstaller {
221
231
}
222
232
223
233
impl NixInstaller {
234
+ /// Detect the Nix installer
224
235
pub fn detect ( ) -> Result < Self , NixEnvError > {
225
236
match super :: detsys_installer:: DetSysNixInstaller :: detect ( ) ? {
226
237
Some ( installer) => Ok ( NixInstaller :: DetSys ( installer) ) ,
@@ -230,18 +241,17 @@ impl NixInstaller {
230
241
}
231
242
232
243
/// Errors while trying to fetch [NixEnv]
233
-
234
244
#[ derive( thiserror:: Error , Debug ) ]
235
245
pub enum NixEnvError {
236
- #[ error( "Cannot find $USER: {0}" ) ]
237
- UserError ( #[ from] std:: env:: VarError ) ,
238
-
246
+ /// Unable to find user groups
239
247
#[ error( "Failed to fetch groups: {0}" ) ]
240
248
GroupsError ( std:: io:: Error ) ,
241
249
250
+ /// Unable to find /nix volume
242
251
#[ error( "Unable to find root disk or /nix volume" ) ]
243
252
NoDisk ,
244
253
254
+ /// Unable to find Nix installer
245
255
#[ error( "Failed to detect Nix installer: {0}" ) ]
246
256
InstallerError ( #[ from] super :: detsys_installer:: BadInstallerVersion ) ,
247
257
}
0 commit comments