hosts/RyanMac/configuration.nix

2bead7efb473f0202dc6ef189fbc0e4a5401d41f · 14.7 KB · 434 lines raw

1 { config, 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
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 = "10";
81 mouse_modifier = "alt";
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 yabai -m rule --add app="^Zen$" title="^Picture-in-Picture$" manage=off
90 ''
91 # Add simple-bar signals if enabled
92 + lib.optionalString config.home-manager.users.${username}.ryan.simple-bar.enable ''
93 yabai -m signal --add event=window_focused action="curl http://localhost:7776/yabai/spaces/refresh && curl http://localhost:7776/yabai/windows/refresh" label="Refresh simple-bar spaces & windows when focused application changes"
94 yabai -m signal --add event=window_resized action="curl http://localhost:7776/yabai/spaces/refresh && curl http://localhost:7776/yabai/windows/refresh" label="Refresh simple-bar spaces & windows when a window is resized"
95 yabai -m signal --add event=window_destroyed action="curl http://localhost:7776/yabai/spaces/refresh && curl http://localhost:7776/yabai/windows/refresh" label="Refresh simple-ba spaces & windows when an application window is closed"
96 yabai -m signal --add event=space_changed action="curl http://localhost:7776/yabai/spaces/refresh && curl http://localhost:7776/yabai/windows/refresh" label="Refresh simple-bar spaces & windows on space change"
97 yabai -m signal --add event=display_changed action="curl http://localhost:7776/yabai/spaces/refresh && curl http://localhost:7776/yabai/windows/refresh" label="Refresh simple-bar spaces & windows on display focus change"
98 yabai -m signal --add event=window_title_changed action="curl http://localhost:7776/yabai/spaces/refresh && curl http://localhost:7776/yabai/windows/refresh" label="Refresh simple-bar spaces & windows when current window title changes"
99 yabai -m signal --add event=space_destroyed action="curl http://localhost:7776/yabai/spaces/refresh && curl http://localhost:7776/yabai/windows/refresh" label="Refresh simple-bar spaces & windows on space removal"
100 yabai -m signal --add event=space_created action="curl http://localhost:7776/yabai/spaces/refresh && curl http://localhost:7776/yabai/windows/refresh" label="Refresh simple-bar spaces & windows on space creation"
101 yabai -m signal --add event=application_activated action="curl http://localhost:7776/yabai/spaces/refresh && curl http://localhost:7776/yabai/windows/refresh" label="Refresh simple-bar spaces & windows when application is activated"
102 yabai -m signal --add event=display_added action="curl http://localhost:7776/yabai/displays/refresh" label="Refresh simple-bar displays when a new dispay is added"
103 yabai -m signal --add event=display_removed action="curl http://localhost:7776/yabai/displays/refresh" label="Refresh simple-bar displays when a dispay is removed"
104 yabai -m signal --add event=display_moved action="curl http://localhost:7776/yabai/displays/refresh" label="Refresh simple-bar displays when a dispay is moved"
105 '';
106 };
107
108 # Configure JankyBorders
109 services.jankyborders = {
110 enable = true;
111 style = "round";
112 width = 6.0;
113 hidpi = true;
114 ax_focus = true;
115 active_color = "gradient(top_left=0xee33ccff,bottom_right=0xee00ff99)";
116 inactive_color = "0xaa595959";
117 };
118
119 # Install the /etc/nix/flake-registry.json file we made above
120 environment.etc."nix/flake-registry.json".source = pinnedNixpkgs;
121
122 # Install RyanCA Root
123 security.pki.certificateFiles = [
124 ../../files/CACerts/RyanCA.crt
125 ];
126
127 # Virby linux builder
128 services.virby = {
129 enable = true;
130 cores = 4;
131 diskSize = "50GiB";
132 onDemand = {
133 enable = true;
134 ttl = 30;
135 };
136 rosetta = true;
137 };
138
139 nix = {
140 enable = true;
141 settings = {
142 flake-registry = "/etc/nix/flake-registry.json";
143 extra-substituters = [
144 "https://virby-nix-darwin.cachix.org"
145 ];
146 extra-trusted-public-keys = [
147 "virby-nix-darwin.cachix.org-1:z9GiEZeBU5bEeoDQjyfHPMGPBaIQJOOvYOOjGMKIlLo="
148 ];
149 "extra-experimental-features" = [ "nix-command" "flakes" ];
150 };
151 };
152
153 # Determines the nix-darwin release compatibility
154 system.stateVersion = 6;
155
156 # System profile programs
157 programs = {
158 zsh.enable = true;
159 };
160
161 # Install homebrew itself
162 nix-homebrew = {
163 enable = true;
164 enableRosetta = true;
165 user = "${username}";
166 mutableTaps = false;
167 taps = thirdPartyTaps;
168 trust.taps = builtins.attrNames thirdPartyTaps;
169 };
170
171 # Install homebrew casks/apps
172 homebrew = {
173 enable = true;
174
175 onActivation = {
176 cleanup = "zap";
177 };
178
179 global.brewfile = true;
180
181 taps = builtins.attrNames thirdPartyTaps;
182
183 brews = [
184 "mqttx-cli"
185 ];
186
187 casks = [
188 "utm"
189 "ghostty"
190 "zen"
191 "ungoogled-chromium"
192 "tailscale-app"
193 "netbird-ui"
194 "ubersicht"
195 "hammerspoon"
196 ];
197 };
198
199 # Keyboard shortcuts using skhd
200 services.skhd = {
201 enable = true;
202 skhdConfig = ''
203 alt - d : osascript -e 'tell application "System Events" to key code 49 using {command down}'
204 alt - return : osascript -e 'tell application "Ghostty"' -e 'new window' -e 'activate' -e 'end tell'
205
206 shift + alt - q : ${pkgs.yabai}/bin/yabai -m window --close
207
208 alt - up : ${pkgs.yabai}/bin/yabai -m window --focus north || ${pkgs.yabai}/bin/yabai -m display --focus north
209 shift + alt - up : ${pkgs.yabai}/bin/yabai -m window --swap north || ${pkgs.yabai}/bin/yabai -m window --display north
210 alt - down : ${pkgs.yabai}/bin/yabai -m window --focus south || ${pkgs.yabai}/bin/yabai -m display --focus south
211 shift + alt - down : ${pkgs.yabai}/bin/yabai -m window --swap south || ${pkgs.yabai}/bin/yabai -m window --display south
212 alt - right : ${pkgs.yabai}/bin/yabai -m window --focus east || ${pkgs.yabai}/bin/yabai -m display --focus east
213 shift + alt - right : ${pkgs.yabai}/bin/yabai -m window --swap east || ${pkgs.yabai}/bin/yabai -m window --display east
214 alt - left : ${pkgs.yabai}/bin/yabai -m window --focus west || ${pkgs.yabai}/bin/yabai -m display --focus west
215 shift + alt - left: ${pkgs.yabai}/bin/yabai -m window --swap west || ${pkgs.yabai}/bin/yabai -m window --display west
216
217 shift + alt - space: ${pkgs.yabai}/bin/yabai -m window --toggle float
218
219 shift + alt - return: ${pkgs.yabai}/bin/yabai -m window --toggle sticky
220
221 alt - f : ${pkgs.yabai}/bin/yabai -m window --toggle zoom-fullscreen
222
223 shift + alt - f: ${pkgs.yabai}/bin/yabai -m window --toggle native-fullscreen
224
225 shift + alt - 1 : ${pkgs.yabai}/bin/yabai -m window --space 1
226 shift + alt - 2 : ${pkgs.yabai}/bin/yabai -m window --space 2
227 shift + alt - 3 : ${pkgs.yabai}/bin/yabai -m window --space 3
228 shift + alt - 4 : ${pkgs.yabai}/bin/yabai -m window --space 4
229 shift + alt - 5 : ${pkgs.yabai}/bin/yabai -m window --space 5
230 shift + alt - 6 : ${pkgs.yabai}/bin/yabai -m window --space 6
231 shift + alt - 7 : ${pkgs.yabai}/bin/yabai -m window --space 7
232 shift + alt - 8 : ${pkgs.yabai}/bin/yabai -m window --space 8
233 shift + alt - 9 : ${pkgs.yabai}/bin/yabai -m window --space 9
234 '';
235 };
236
237 # System configuration
238 time.timeZone = "America/New_York";
239
240 power.sleep = {
241 display = 10;
242 computer = 30;
243 };
244
245 system.defaults = {
246 WindowManager = {
247 EnableTilingOptionAccelerator = false;
248 };
249 NSGlobalDomain = {
250 # 24 hour time
251 AppleICUForce24HourTime = true;
252
253 # Dark Mode
254 AppleInterfaceStyle = "Dark";
255
256 # Key repeat rate
257 KeyRepeat = 4;
258 InitialKeyRepeat = 30;
259
260 # Swap F1-12 to be default
261 "com.apple.keyboard.fnState" = true;
262
263 # Disable Keyboard bullcrap
264 NSAutomaticCapitalizationEnabled = false;
265 NSAutomaticDashSubstitutionEnabled = false;
266 NSAutomaticPeriodSubstitutionEnabled = false;
267 NSAutomaticQuoteSubstitutionEnabled = false;
268 NSAutomaticSpellingCorrectionEnabled = false;
269 ApplePressAndHoldEnabled = false;
270 };
271
272 # screensaver/power settings
273 screensaver = {
274 askForPassword = true;
275 askForPasswordDelay = 0;
276 };
277
278 # Control center stuff
279 controlcenter = {
280 BatteryShowPercentage = true;
281 Bluetooth = true;
282 };
283
284 # Clock settings
285 menuExtraClock = {
286 Show24Hour = true;
287 ShowDate = 1; # Always
288 ShowDayOfWeek = true;
289 ShowSeconds = true;
290 };
291
292 # Screen capture settings
293 screencapture = {
294 target = "clipboard";
295 type = "png";
296 };
297
298 # finder good settings
299 finder = {
300 AppleShowAllExtensions = true;
301 AppleShowAllFiles = true;
302 ShowPathbar = true;
303 FXEnableExtensionChangeWarning = false;
304 _FXShowPosixPathInTitle = true;
305 NewWindowTarget = "Home";
306 ShowExternalHardDrivesOnDesktop = false;
307 ShowHardDrivesOnDesktop = false;
308 ShowMountedServersOnDesktop = false;
309 ShowRemovableMediaOnDesktop = false;
310 ShowStatusBar = true;
311 };
312
313 spaces = {
314 "spans-displays" = false; # independent spaces per display
315 };
316
317 # Login Window Settings
318 loginwindow = {
319 GuestEnabled = false;
320 DisableConsoleAccess = true;
321 };
322
323 # dock settings
324 dock = {
325 magnification = true;
326 largesize = 96;
327 tilesize = 32;
328 minimize-to-application = false;
329 orientation = "bottom";
330 autohide = true;
331 mru-spaces = false; # Disable auto-rearrange spaces
332 persistent-apps = [
333 { app = "/Applications/Zen.app"; }
334 #{ app = "/System/Applications/Launchpad.app"; }
335 { app = "/System/Applications/Messages.app"; }
336 { app = "/System/Applications/Facetime.app"; }
337 { app = "/System/Applications/Calendar.app"; }
338 { app = "/System/Applications/App Store.app"; }
339 { app = "/System/Applications/System Settings.app"; }
340 { app = "/Applications/Ghostty.app"; }
341 { app = "/Applications/UTM.app"; }
342 ];
343 persistent-others = [
344 { folder = { path = "/Users/${username}/Downloads"; showas = "grid"; arrangement = "date-created"; }; }
345 { folder = { path = "/Users/${username}/Applications"; showas = "grid"; arrangement = "name"; }; }
346 ];
347 show-recents = false;
348 };
349
350 # Custom preferences
351 CustomUserPreferences = {
352 NSGlobalDomain = {
353 # Always show menu bar
354 AppleMenuBarVisibleInFullscreen = true;
355
356 # Hide the menubar by default
357 "_HIHideMenuBar" = true;
358
359 # Option + L lock
360 NSUserKeyEquivalents = {
361 "Lock Screen" = "~l";
362 };
363 };
364
365 "com.apple.desktopservices" = {
366 DSDontWriteNetworkStores = true;
367 DSDontWriteUSBStores = true;
368 };
369
370 "com.apple.WindowManager" = {
371 EnableStandardClickToShowDesktop = false;
372 StandardHideDesktopIcons = false;
373 };
374
375 "com.apple.screensaver" = {
376 askForPassword = true;
377 askForPasswordDelay = 2;
378 };
379
380 "com.apple.AdLib" = {
381 allowApplePersonalizedAdvertising = false;
382 };
383
384 "com.apple.Accessibility" = {
385 ReduceMotionEnabled = 1;
386 };
387
388 "com.apple.symbolichotkeys" = {
389 AppleSymbolicHotKeys = manualHotkeys // spaceHotkeys;
390 };
391 };
392 universalaccess.reduceMotion = true;
393 };
394
395 # Post-Activation scripts
396 system.activationScripts.postActivation.text = ''
397 echo "Configuring NTP servers..."
398 systemsetup -setnetworktimeserver pool.ntp.org > /dev/null 2>&1 || true
399 systemsetup -setusingnetworktime on > /dev/null 2>&1 || true
400
401 ryancasum="$(${pkgs.openssl}/bin/openssl x509 -in "${../../files/CACerts/RyanCA.crt}" -noout -fingerprint -sha1 | sed 's/.*=//; s/://g')"
402 if ! /usr/bin/security find-certificate -a -Z "/Library/Keychains/System.keychain" | tr -d ':' | grep -iq "$ryancasum"; then
403 echo "Installing RyanCA Certificate..."
404 /usr/bin/security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ${../../files/CACerts/RyanCA.crt}
405 fi
406
407 echo "Reloading Preferences DB..."
408 sudo -iu ${username} /System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u
409
410 echo "Setting default browser"
411 ${pkgs.defaultbrowser}/bin/defaultbrowser ${defaultBrowser}
412
413 echo "Adding Keyboard brightness controls to Control Center..."
414 sudo -iu ${username} defaults -currentHost write com.apple.controlcenter KeyboardBrightness -int 25
415
416 # this is fragile so it goes at the bottom
417 echo "Reloading skhd..."
418 sudo -iu ${username} ${pkgs.skhd}/bin/skhd -r
419
420 # 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
421 MARK="/opt/.nix-complete"
422 if [ ! -f "$MARK" ]; then
423 echo "o0o0o0o0o0o MacOS Initial Deploy Notes o0o0o0o0o0o"
424 echo "--------------------------------------------------"
425 echo "The following actions must be taken since they are not configurable by Nix. This must be done only ONCE."
426 echo ""
427 echo "1. Create 9 spaces."
428 echo "2. Set keyboard autofill settings"
429 echo "--------------------------------------------------"
430 fi
431 touch "$MARK"
432 '';
433
434 }