hosts/RyanMac/configuration.nix

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