hosts/RyanMac/configuration.nix

397af8b5b8bf6d08f26292207ce2aaffc095772b · 15.1 KB · 441 lines raw

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