hosts/RyanMac/configuration.nix

b46d42c560eb97f214d0b767c0ffee44711ecfba · 9.9 KB · 351 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 alt - d : osascript -e 'tell application "System Events" to key code 49 using {command down}'
155 alt - return : osascript -e 'tell application "Ghostty"' -e 'new window' -e 'activate' -e 'end tell'
156
157 alt - up : ${pkgs.yabai}/bin/yabai -m window --focus north
158 shift + alt - up : ${pkgs.yabai}/bin/yabai -m window --swap north
159 alt - down : ${pkgs.yabai}/bin/yabai -m window --focus south
160 shift + alt - down : ${pkgs.yabai}/bin/yabai -m window --swap south
161 alt - right : ${pkgs.yabai}/bin/yabai -m window --focus east
162 shift + alt - right : ${pkgs.yabai}/bin/yabai -m window --swap east
163 alt - left : ${pkgs.yabai}/bin/yabai -m window --focus west
164 shift + alt - left: ${pkgs.yabai}/bin/yabai -m window --swap west
165
166 shift + alt - 1 : ${pkgs.yabai}/bin/yabai -m window --space 1
167 shift + alt - 2 : ${pkgs.yabai}/bin/yabai -m window --space 2
168 shift + alt - 3 : ${pkgs.yabai}/bin/yabai -m window --space 3
169 shift + alt - 4 : ${pkgs.yabai}/bin/yabai -m window --space 4
170 shift + alt - 5 : ${pkgs.yabai}/bin/yabai -m window --space 5
171 shift + alt - 6 : ${pkgs.yabai}/bin/yabai -m window --space 6
172 shift + alt - 7 : ${pkgs.yabai}/bin/yabai -m window --space 7
173 shift + alt - 8 : ${pkgs.yabai}/bin/yabai -m window --space 8
174 shift + alt - 9 : ${pkgs.yabai}/bin/yabai -m window --space 9
175
176 alt - f : ${pkgs.yabai}/bin/yabai -m window --toggle zoom-fullscreen
177 '';
178 };
179
180 # System configuration
181 time.timeZone = "America/New_York";
182
183 power.sleep = {
184 display = 10;
185 computer = 30;
186 };
187
188 system.defaults = {
189 NSGlobalDomain = {
190 # 24 hour time
191 AppleICUForce24HourTime = true;
192
193 # Dark Mode
194 AppleInterfaceStyle = "Dark";
195
196 # Key repeat rate
197 KeyRepeat = 4;
198 InitialKeyRepeat = 30;
199
200 # Swap F1-12 to be default
201 "com.apple.keyboard.fnState" = true;
202
203 # Disable Keyboard bullcrap
204 NSAutomaticCapitalizationEnabled = false;
205 NSAutomaticDashSubstitutionEnabled = false;
206 NSAutomaticPeriodSubstitutionEnabled = false;
207 NSAutomaticQuoteSubstitutionEnabled = false;
208 NSAutomaticSpellingCorrectionEnabled = false;
209 ApplePressAndHoldEnabled = false;
210 };
211
212 # screensaver/power settings
213 screensaver = {
214 askForPassword = true;
215 askForPasswordDelay = 0;
216 };
217
218 # Control center stuff
219 controlcenter = {
220 BatteryShowPercentage = true;
221 Bluetooth = true;
222 };
223
224 # Clock settings
225 menuExtraClock = {
226 Show24Hour = true;
227 ShowDate = 1; # Always
228 ShowDayOfWeek = true;
229 ShowSeconds = true;
230 };
231
232 # Screen capture settings
233 screencapture = {
234 target = "clipboard";
235 type = "png";
236 };
237
238 # finder good settings
239 finder = {
240 AppleShowAllExtensions = true;
241 AppleShowAllFiles = true;
242 ShowPathbar = true;
243 FXEnableExtensionChangeWarning = false;
244 _FXShowPosixPathInTitle = true;
245 NewWindowTarget = "Home";
246 ShowExternalHardDrivesOnDesktop = false;
247 ShowHardDrivesOnDesktop = false;
248 ShowMountedServersOnDesktop = false;
249 ShowRemovableMediaOnDesktop = false;
250 ShowStatusBar = true;
251 };
252
253 spaces = {
254 "spans-displays" = false; # independent spaces per display
255 };
256
257 # Login Window Settings
258 loginwindow = {
259 GuestEnabled = false;
260 DisableConsoleAccess = true;
261 };
262
263 # dock settings
264 dock = {
265 magnification = true;
266 largesize = 96;
267 tilesize = 32;
268 minimize-to-application = false;
269 orientation = "bottom";
270 autohide = true;
271 mru-spaces = false; # Disable auto-rearrange spaces
272 persistent-apps = [
273 { app = "/Applications/Zen.app"; }
274 #{ app = "/System/Applications/Launchpad.app"; }
275 { app = "/System/Applications/Messages.app"; }
276 { app = "/System/Applications/Facetime.app"; }
277 { app = "/System/Applications/Calendar.app"; }
278 { app = "/System/Applications/App Store.app"; }
279 { app = "/System/Applications/System Settings.app"; }
280 { app = "/Applications/UTM.app"; }
281 ];
282 persistent-others = [
283 { folder = { path = "/Users/${username}/Downloads"; showas = "grid"; arrangement = "date-created"; }; }
284 { folder = { path = "/Users/${username}/Applications"; showas = "grid"; arrangement = "name"; }; }
285 ];
286 show-recents = false;
287 };
288
289 # Custom preferences
290 CustomUserPreferences = {
291 NSGlobalDomain = {
292 # Always show menu bar
293 AppleMenuBarVisibleInFullscreen = true;
294
295 # Option + L lock
296 NSUserKeyEquivalents = {
297 "Lock Screen" = "~l";
298 };
299 };
300
301 "com.apple.Accessibility" = {
302 ReduceMotionEnabled = 1;
303 };
304
305 "com.apple.symbolichotkeys" = {
306 AppleSymbolicHotKeys = manualHotkeys // spaceHotkeys;
307 };
308 };
309 universalaccess.reduceMotion = true;
310 };
311
312 # Post-Activation scripts
313 system.activationScripts.postActivation.text = ''
314 echo "Configuring NTP servers..."
315 systemsetup -setnetworktimeserver pool.ntp.org > /dev/null 2>&1 || true
316 systemsetup -setusingnetworktime on > /dev/null 2>&1 || true
317
318 ryancasum="$(${pkgs.openssl}/bin/openssl x509 -in "${../../files/CACerts/RyanCA.crt}" -noout -fingerprint -sha1 | sed 's/.*=//; s/://g')"
319 if ! /usr/bin/security find-certificate -a -Z "/Library/Keychains/System.keychain" | tr -d ':' | grep -iq "$ryancasum"; then
320 echo "Installing RyanCA Certificate..."
321 /usr/bin/security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ${../../files/CACerts/RyanCA.crt}
322 fi
323
324 echo "Reloading Preferences DB..."
325 sudo -iu ${username} /System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u
326
327 echo "Setting default browser"
328 ${pkgs.defaultbrowser}/bin/defaultbrowser ${defaultBrowser}
329
330 echo "Adding Keyboard brightness controls to Control Center..."
331 sudo -iu ${username} defaults -currentHost write com.apple.controlcenter KeyboardBrightness -int 25
332
333 # this is fragile so it goes at the bottom
334 echo "Reloading skhd..."
335 sudo -iu ${username} ${pkgs.skhd}/bin/skhd -r
336
337 # 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
338 MARK="/opt/.nix-complete"
339 if [ ! -f "$MARK" ]; then
340 echo "o0o0o0o0o0o MacOS Initial Deploy Notes o0o0o0o0o0o"
341 echo "--------------------------------------------------"
342 echo "The following actions must be taken since they are not configurable by Nix. This must be done only ONCE."
343 echo ""
344 echo "1. Create 9 spaces."
345 echo "2. Set a wallpaper as visible in all spaces."
346 echo "--------------------------------------------------"
347 fi
348 touch "$MARK"
349 '';
350
351 }