hosts/RyanMac/configuration.nix

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