summaryrefslogtreecommitdiff
path: root/hosts/RyanMac/configuration.nix
blob: 572c534b76fb60ca44a87075c0f7fa7ff03a430a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
{ pkgs, inputs, ... }:
let
  username = "ryan";

  defaultBrowser = "zen";

  pinnedNixpkgs = pkgs.writeText "flake-registry.json" (builtins.toJSON {
    version = 2;
    flakes = [
      {
        from = { type = "indirect"; id = "nixpkgs"; };
	to = {
	  type = "path";
	  path = inputs.nixpkgs.outPath;
	  lastModified = inputs.nixpkgs.lastModified;
	  narHash = inputs.nixpkgs.narHash;
	};
      }
    ];
  });

in {
  # Define the system's user and home dir location
  users.users."${username}" = {
    name = "${username}";
    home = "/Users/${username}";
  };

  system.primaryUser = "${username}";

  # Install the /etc/nix/flake-registry.json file we made above
  environment.etc."nix/flake-registry.json".source = pinnedNixpkgs;

  # Install RyanCA Root
  security.pki.certificateFiles = [
    ../../files/CACerts/RyanCA.crt
  ];

  # Need to disable native nix handling because of Determinate nix
  determinateNix = {
    enable = true;
    customSettings = {
      flake-registry = "/etc/nix/flake-registry.json";
    };
  };

  # Determines the nix-darwin release compatibility
  system.stateVersion = 6;

  # System profile programs
  programs = {
	zsh.enable = true;
  };

  # Install homebrew casks/apps
  homebrew = {
    enable = true;

    onActivation = {
      cleanup = "zap";
      extraFlags = [ "--force-cleanup" ];
    };

    casks = [
      "utm"
      "ghostty"
      "zen"
    ];
  };

  # Keyboard shortcuts using skhd
  services.skhd = {
    enable = true;
    skhdConfig = ''
      alt - d : osascript -e 'tell application "System Events" to key code 49 using {command down}'
      alt - return : open -na /Applications/Ghostty.app
    '';
    };

  # System configuration
  time.timeZone = "America/New_York";

  system.defaults = {
    NSGlobalDomain = {
      # 24 hour time
      AppleICUForce24HourTime = true;

      # Dark Mode
      AppleInterfaceStyle = "Dark";

      # Key repeat rate
      KeyRepeat = 4;
      InitialKeyRepeat = 30;

      # Swap F1-12 to be default
      "com.apple.keyboard.fnState" = true;

      # Disable Keyboard bullcrap
      NSAutomaticCapitalizationEnabled = false;
      NSAutomaticDashSubstitutionEnabled = false;
      NSAutomaticPeriodSubstitutionEnabled = false;
      NSAutomaticQuoteSubstitutionEnabled = false;
      NSAutomaticSpellingCorrectionEnabled = false;
      ApplePressAndHoldEnabled = false;
    };

    # Control center stuff
    controlcenter = {
      BatteryShowPercentage = true;
    };

    # Clock settings
    menuExtraClock = {
      Show24Hour = true;
      ShowDate = 1; # Always
      ShowDayOfWeek = true;
      ShowSeconds = true;
    };

    # Screen capture settings
    screencapture = {
      target = "clipboard";
      type = "png";
    };

    # finder good settings
    finder = {
      AppleShowAllExtensions = true;
      AppleShowAllFiles = true;
      ShowPathbar = true;
      FXEnableExtensionChangeWarning = false;
      _FXShowPosixPathInTitle = true;
      NewWindowTarget = "Home";
      ShowExternalHardDrivesOnDesktop = false;
      ShowHardDrivesOnDesktop = false;
      ShowMountedServersOnDesktop = false;
      ShowRemovableMediaOnDesktop = false;
      ShowStatusBar = true;
    };

    # Login Window Settings
    loginwindow = {
      GuestEnabled = false;
      DisableConsoleAccess = true;
    };

    # dock settings
    dock = {
      magnification = true;
      largesize = 96;
      tilesize = 32;
      minimize-to-application = false;
      orientation = "bottom";
      autohide = true;
      persistent-apps = [
        { app = "/Applications/Zen.app"; }
        #{ app = "/System/Applications/Launchpad.app"; }
        { app = "/System/Applications/Messages.app"; }
        { app = "/System/Applications/Facetime.app"; }
        { app = "/System/Applications/Calendar.app"; }
        { app = "/System/Applications/App Store.app"; }
        { app = "/System/Applications/System Settings.app"; }
        { app = "/Applications/UTM.app"; }
      ];
      persistent-others = [
        { folder = { path = "/Users/${username}/Downloads"; showas = "grid"; arrangement = "date-created"; }; }
        { folder = { path = "/Applications"; showas = "grid"; arrangement = "name"; }; }
      ];
      show-recents = false;
    };

    # Custom preferences
    CustomUserPreferences = {
      NSGlobalDomain = {
        # Always show menu bar
        AppleMenuBarVisibleInFullscreen = true;
      };

      "com.apple.symbolichotkeys" = {
        AppleSymbolicHotKeys = {
          "64" = {
            enabled = true; # skhd needs this for its shortcut
          };
        };
      };
    };
  };

  # Post-Activation scripts
  system.activationScripts.postActivation.text = ''
    echo "Configuring NTP servers..."
    systemsetup -setnetworktimeserver pool.ntp.org > /dev/null 2>&1 || true
    systemsetup -setusingnetworktime on > /dev/null 2>&1 || true

    ryancasum="$(${pkgs.openssl}/bin/openssl x509 -in "${../../files/CACerts/RyanCA.crt}" -noout -fingerprint -sha1 | sed 's/.*=//; s/://g')"
    if ! /usr/bin/security find-certificate -a -Z "/Library/Keychains/System.keychain" | tr -d ':' | grep -iq "$ryancasum"; then
      echo "Installing RyanCA Certificate..."
      /usr/bin/security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ${../../files/CACerts/RyanCA.crt}
    fi

    echo "Reloading Preferences DB..."
    /System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u

    echo "Setting default browser"
    ${pkgs.defaultbrowser}/bin/defaultbrowser ${defaultBrowser}

    # this is fragile so it goes at the bottom
    echo "Reloading skhd..."
    sudo -iu ${username} ${pkgs.skhd}/bin/skhd -r
  '';

}