hosts/RyanMac/configuration.nix

78690d5e544616e73562e13d0c27bd910480111c · 11.5 KB · 394 lines raw

1 { pkgs, inputs, lib, ... }:
2 let
3 username = "ryan";
4
5 defaultBrowser = "zen";
6
7 thirdPartyTaps = import ./taps.nix;
8
9 pinnedNixpkgs = pkgs.writeText "flake-registry.json" (builtins.toJSON {
10 version = 2;
11 flakes = [
12 {
13 from = { type = "indirect"; id = "nixpkgs"; };
14 to = {
15 type = "path";
16 path = inputs.nixpkgs.outPath;
17 lastModified = inputs.nixpkgs.lastModified;
18 narHash = inputs.nixpkgs.narHash;
19 };
20 }
21 ];
22 });
23
24 mkSpace = i: {
25 name = toString (117+i);
26 value = {
27 enabled = true;
28 value = {
29 type = "standard";
30 #parameters = [ (48 + i) (builtins.elemAt [ 18 19 20 21 22 23 25 26 28 ] (i - 1)) 524288 ]; # opt + num
31 parameters = [ (48 + i) (builtins.elemAt [ 18 19 20 21 22 23 25 26 28 ] (i - 1)) 1048576 ]; # cmd + num
32 };
33 };
34 };
35
36 spaceHotkeys = builtins.listToAttrs (map mkSpace (lib.range 1 9));
37
38 manualHotkeys = {
39 "64" = {
40 enabled = true;
41 };
42 };
43
44 in {
45 # Modules
46 imports = [
47 inputs.nix-homebrew.darwinModules.nix-homebrew
48 ../../modules/darwin/random-wallpaper/module.nix
49 ];
50
51 # Define the system's user and home dir location
52 users.users."${username}" = {
53 name = "${username}";
54 home = "/Users/${username}";
55 };
56
57 system.primaryUser = "${username}";
58
59 # Set the hostname for this machine
60 networking.hostName = "RyanMac";
61
62 # Install the wallpaper engine
63 local.randomWallpaper = {
64 enable = true;
65 directory = "${../../files/Wallpapers}";
66 };
67
68 # Configure yabai
69 services.yabai = {
70 enable = true;
71 enableScriptingAddition = false;
72 config = {
73 mouse_follows_focus = "on";
74 layout = "bsp";
75 window_placement = "second_child";
76 top_padding = "10";
77 bottom_padding = "10";
78 left_padding = "10";
79 right_padding = "10";
80 window_gap = "5";
81 mouse_modifier = "cmd";
82 mouse_drop_action = "swap";
83 mouse_action1 = "move";
84 mouse_action2 = "resize";
85 focus_follows_mouse = "autofocus";
86 };
87 extraConfig = ''
88 yabai -m rule --add app='System Settings' manage=off
89 '';
90 };
91
92 # Configure JankyBorders
93 services.jankyborders = {
94 enable = true;
95 style = "round";
96 width = 6.0;
97 hidpi = true;
98 ax_focus = true;
99 active_color = "gradient(top_left=0xee33ccff,bottom_right=0xee00ff99)";
100 inactive_color = "0xaa595959";
101 };
102
103 # Install the /etc/nix/flake-registry.json file we made above
104 environment.etc."nix/flake-registry.json".source = pinnedNixpkgs;
105
106 # Install RyanCA Root
107 security.pki.certificateFiles = [
108 ../../files/CACerts/RyanCA.crt
109 ];
110
111 nix = {
112 enable = true;
113 settings = {
114 flake-registry = "/etc/nix/flake-registry.json";
115 "extra-experimental-features" = [ "nix-command" "flakes" ];
116 };
117 };
118
119 # Determines the nix-darwin release compatibility
120 system.stateVersion = 6;
121
122 # System profile programs
123 programs = {
124 zsh.enable = true;
125 };
126
127 # Install homebrew itself
128 nix-homebrew = {
129 enable = true;
130 enableRosetta = true;
131 user = "${username}";
132 mutableTaps = false;
133 taps = thirdPartyTaps;
134 trust.taps = builtins.attrNames thirdPartyTaps;
135 };
136
137 # Install homebrew casks/apps
138 homebrew = {
139 enable = true;
140
141 onActivation = {
142 cleanup = "zap";
143 };
144
145 global.brewfile = true;
146
147 taps = builtins.attrNames thirdPartyTaps;
148
149 brews = [
150 "mqttx-cli"
151 ];
152
153 casks = [
154 "utm"
155 "ghostty"
156 "zen"
157 "ungoogled-chromium"
158 "tailscale-app"
159 "netbird-ui"
160 ];
161 };
162
163 # Keyboard shortcuts using skhd
164 services.skhd = {
165 enable = true;
166 skhdConfig = ''
167 cmd - d : osascript -e 'tell application "System Events" to key code 49 using {command down}'
168 cmd - return : osascript -e 'tell application "Ghostty"' -e 'new window' -e 'activate' -e 'end tell'
169
170 shift + cmd - q : ${pkgs.yabai}/bin/yabai -m window --close
171
172 cmd - up : ${pkgs.yabai}/bin/yabai -m window --focus north || ${pkgs.yabai}/bin/yabai -m display --focus north
173 shift + cmd - up : ${pkgs.yabai}/bin/yabai -m window --swap north || ${pkgs.yabai}/bin/yabai -m window --display north
174 cmd - down : ${pkgs.yabai}/bin/yabai -m window --focus south || ${pkgs.yabai}/bin/yabai -m display --focus south
175 shift + cmd - down : ${pkgs.yabai}/bin/yabai -m window --swap south || ${pkgs.yabai}/bin/yabai -m window --display south
176 cmd - right : ${pkgs.yabai}/bin/yabai -m window --focus east || ${pkgs.yabai}/bin/yabai -m display --focus east
177 shift + cmd - right : ${pkgs.yabai}/bin/yabai -m window --swap east || ${pkgs.yabai}/bin/yabai -m window --display east
178 cmd - left : ${pkgs.yabai}/bin/yabai -m window --focus west || ${pkgs.yabai}/bin/yabai -m display --focus west
179 shift + cmd - left: ${pkgs.yabai}/bin/yabai -m window --swap west || ${pkgs.yabai}/bin/yabai -m window --display west
180
181 shift + cmd - space: ${pkgs.yabai}/bin/yabai -m window --toggle float
182
183 shift + cmd - return: ${pkgs.yabai}/bin/yabai -m window --toggle sticky
184
185 cmd - f : ${pkgs.yabai}/bin/yabai -m window --toggle zoom-fullscreen
186
187 shift + cmd - f: ${pkgs.yabai}/bin/yabai -m window --toggle native-fullscreen
188
189 shift + cmd - 1 : ${pkgs.yabai}/bin/yabai -m window --space 1
190 shift + cmd - 2 : ${pkgs.yabai}/bin/yabai -m window --space 2
191 shift + cmd - 3 : ${pkgs.yabai}/bin/yabai -m window --space 3
192 shift + cmd - 4 : ${pkgs.yabai}/bin/yabai -m window --space 4
193 shift + cmd - 5 : ${pkgs.yabai}/bin/yabai -m window --space 5
194 shift + cmd - 6 : ${pkgs.yabai}/bin/yabai -m window --space 6
195 shift + cmd - 7 : ${pkgs.yabai}/bin/yabai -m window --space 7
196 shift + cmd - 8 : ${pkgs.yabai}/bin/yabai -m window --space 8
197 shift + cmd - 9 : ${pkgs.yabai}/bin/yabai -m window --space 9
198 '';
199 };
200
201 # System configuration
202 time.timeZone = "America/New_York";
203
204 power.sleep = {
205 display = 10;
206 computer = 30;
207 };
208
209 system.defaults = {
210 NSGlobalDomain = {
211 # 24 hour time
212 AppleICUForce24HourTime = true;
213
214 # Dark Mode
215 AppleInterfaceStyle = "Dark";
216
217 # Key repeat rate
218 KeyRepeat = 4;
219 InitialKeyRepeat = 30;
220
221 # Swap F1-12 to be default
222 "com.apple.keyboard.fnState" = true;
223
224 # Disable Keyboard bullcrap
225 NSAutomaticCapitalizationEnabled = false;
226 NSAutomaticDashSubstitutionEnabled = false;
227 NSAutomaticPeriodSubstitutionEnabled = false;
228 NSAutomaticQuoteSubstitutionEnabled = false;
229 NSAutomaticSpellingCorrectionEnabled = false;
230 ApplePressAndHoldEnabled = false;
231 };
232
233 # screensaver/power settings
234 screensaver = {
235 askForPassword = true;
236 askForPasswordDelay = 0;
237 };
238
239 # Control center stuff
240 controlcenter = {
241 BatteryShowPercentage = true;
242 Bluetooth = true;
243 };
244
245 # Clock settings
246 menuExtraClock = {
247 Show24Hour = true;
248 ShowDate = 1; # Always
249 ShowDayOfWeek = true;
250 ShowSeconds = true;
251 };
252
253 # Screen capture settings
254 screencapture = {
255 target = "clipboard";
256 type = "png";
257 };
258
259 # finder good settings
260 finder = {
261 AppleShowAllExtensions = true;
262 AppleShowAllFiles = true;
263 ShowPathbar = true;
264 FXEnableExtensionChangeWarning = false;
265 _FXShowPosixPathInTitle = true;
266 NewWindowTarget = "Home";
267 ShowExternalHardDrivesOnDesktop = false;
268 ShowHardDrivesOnDesktop = false;
269 ShowMountedServersOnDesktop = false;
270 ShowRemovableMediaOnDesktop = false;
271 ShowStatusBar = true;
272 };
273
274 spaces = {
275 "spans-displays" = false; # independent spaces per display
276 };
277
278 # Login Window Settings
279 loginwindow = {
280 GuestEnabled = false;
281 DisableConsoleAccess = true;
282 };
283
284 # dock settings
285 dock = {
286 magnification = true;
287 largesize = 96;
288 tilesize = 32;
289 minimize-to-application = false;
290 orientation = "bottom";
291 autohide = true;
292 mru-spaces = false; # Disable auto-rearrange spaces
293 persistent-apps = [
294 { app = "/Applications/Zen.app"; }
295 #{ app = "/System/Applications/Launchpad.app"; }
296 { app = "/System/Applications/Messages.app"; }
297 { app = "/System/Applications/Facetime.app"; }
298 { app = "/System/Applications/Calendar.app"; }
299 { app = "/System/Applications/App Store.app"; }
300 { app = "/System/Applications/System Settings.app"; }
301 { app = "/Applications/UTM.app"; }
302 ];
303 persistent-others = [
304 { folder = { path = "/Users/${username}/Downloads"; showas = "grid"; arrangement = "date-created"; }; }
305 { folder = { path = "/Users/${username}/Applications"; showas = "grid"; arrangement = "name"; }; }
306 ];
307 show-recents = false;
308 };
309
310 # Custom preferences
311 CustomUserPreferences = {
312 NSGlobalDomain = {
313 # Always show menu bar
314 AppleMenuBarVisibleInFullscreen = true;
315
316 # Hide the menubar by default
317 "_HIHideMenuBar" = true;
318
319 # Option + L lock
320 NSUserKeyEquivalents = {
321 "Lock Screen" = "~l";
322 };
323 };
324
325 "com.apple.desktopservices" = {
326 DSDontWriteNetworkStores = true;
327 DSDontWriteUSBStores = true;
328 };
329
330 "com.apple.WindowManager" = {
331 EnableStandardClickToShowDesktop = false;
332 StandardHideDesktopIcons = false;
333 };
334
335 "com.apple.screensaver" = {
336 askForPassword = true;
337 askForPasswordDelay = 2;
338 };
339
340 "com.apple.AdLib" = {
341 allowApplePersonalizedAdvertising = false;
342 };
343
344 "com.apple.Accessibility" = {
345 ReduceMotionEnabled = 1;
346 };
347
348 "com.apple.symbolichotkeys" = {
349 AppleSymbolicHotKeys = manualHotkeys // spaceHotkeys;
350 };
351 };
352 universalaccess.reduceMotion = true;
353 };
354
355 # Post-Activation scripts
356 system.activationScripts.postActivation.text = ''
357 echo "Configuring NTP servers..."
358 systemsetup -setnetworktimeserver pool.ntp.org > /dev/null 2>&1 || true
359 systemsetup -setusingnetworktime on > /dev/null 2>&1 || true
360
361 ryancasum="$(${pkgs.openssl}/bin/openssl x509 -in "${../../files/CACerts/RyanCA.crt}" -noout -fingerprint -sha1 | sed 's/.*=//; s/://g')"
362 if ! /usr/bin/security find-certificate -a -Z "/Library/Keychains/System.keychain" | tr -d ':' | grep -iq "$ryancasum"; then
363 echo "Installing RyanCA Certificate..."
364 /usr/bin/security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ${../../files/CACerts/RyanCA.crt}
365 fi
366
367 echo "Reloading Preferences DB..."
368 sudo -iu ${username} /System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u
369
370 echo "Setting default browser"
371 ${pkgs.defaultbrowser}/bin/defaultbrowser ${defaultBrowser}
372
373 echo "Adding Keyboard brightness controls to Control Center..."
374 sudo -iu ${username} defaults -currentHost write com.apple.controlcenter KeyboardBrightness -int 25
375
376 # this is fragile so it goes at the bottom
377 echo "Reloading skhd..."
378 sudo -iu ${username} ${pkgs.skhd}/bin/skhd -r
379
380 # Notes if we are running for the first time and writes a message for actions that may need to be done on macOS or linux
381 MARK="/opt/.nix-complete"
382 if [ ! -f "$MARK" ]; then
383 echo "o0o0o0o0o0o MacOS Initial Deploy Notes o0o0o0o0o0o"
384 echo "--------------------------------------------------"
385 echo "The following actions must be taken since they are not configurable by Nix. This must be done only ONCE."
386 echo ""
387 echo "1. Create 9 spaces."
388 echo "2. Set a wallpaper as visible in all spaces."
389 echo "--------------------------------------------------"
390 fi
391 touch "$MARK"
392 '';
393
394 }