hosts/RyanMac/configuration.nix

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