hosts/RyanMac/configuration.nix

1d64a259eb2f377b7b7dc36263eaf33d4a7cf28c · 8.8 KB · 316 lines raw

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