hosts/RyanMac/configuration.nix

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