hosts/RyanMac/configuration.nix

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