From a635371714e4cc4bc4596a3455780d49fcc96dca Mon Sep 17 00:00:00 2001 From: Stefan Imhoff Date: Wed, 31 Jul 2024 16:45:53 +0200 Subject: [PATCH] feat(nix): migrate MacOS settings to nix-darwin --- darwin/default.nix | 165 +++++++++++++++++++++++++- darwin/homebrew-common.nix | 1 + hosts/mac-mini/configuration.nix | 7 +- {setup => scripts}/deno.sh | 0 {setup => scripts}/golang.sh | 0 {setup => scripts}/init.sh | 10 +- {setup => scripts}/lua.sh | 0 {setup => scripts}/neovim.sh | 0 {setup => scripts}/nodejs.sh | 0 {setup => scripts}/python.sh | 0 {setup => scripts}/ruby.sh | 0 {setup => scripts}/rust.sh | 0 setup/macos.sh | 194 ------------------------------- 13 files changed, 168 insertions(+), 209 deletions(-) rename {setup => scripts}/deno.sh (100%) rename {setup => scripts}/golang.sh (100%) rename {setup => scripts}/init.sh (67%) rename {setup => scripts}/lua.sh (100%) rename {setup => scripts}/neovim.sh (100%) rename {setup => scripts}/nodejs.sh (100%) rename {setup => scripts}/python.sh (100%) rename {setup => scripts}/ruby.sh (100%) rename {setup => scripts}/rust.sh (100%) delete mode 100644 setup/macos.sh diff --git a/darwin/default.nix b/darwin/default.nix index 759f9ab..bb7369b 100644 --- a/darwin/default.nix +++ b/darwin/default.nix @@ -33,14 +33,169 @@ # $ darwin-rebuild changelog system.stateVersion = 4; - system.defaults.NSGlobalDomain.ApplePressAndHoldEnabled = false; - system.defaults.dock.autohide = true; + # General UI/UX + system.defaults.NSGlobalDomain = { + # Set Dark Mode + AppleInterfaceStyle = "Dark"; - system.defaults.NSGlobalDomain.InitialKeyRepeat = 15; - system.defaults.NSGlobalDomain.KeyRepeat = 2; + # Set language and text formats + AppleMeasurementUnits = "Centimeters"; - nixpkgs.hostPlatform = "aarch64-darwin"; + ApplePressAndHoldEnabled = false; + # Finder: show all filename extensions + AppleShowAllExtensions = true; + + # Set a blazingly fast keyboard repeat rate + KeyRepeat = 2; + InitialKeyRepeat = 15; + + # Disable automatic capitalization as it’s annoying when typing code + NSAutomaticCapitalizationEnabled = false; + + # Disable smart dashes as they’re annoying when typing code + NSAutomaticDashSubstitutionEnabled = false; + + # Disable automatic period substitution as it’s annoying when typing code + NSAutomaticPeriodSubstitutionEnabled = false; + + # Disable smart quotes as they’re annoying when typing code + NSAutomaticQuoteSubstitutionEnabled = false; + + # Disable auto-correct + NSAutomaticSpellingCorrectionEnabled = false; + + # Expand save panel by default + NSNavPanelExpandedStateForSaveMode = true; + NSNavPanelExpandedStateForSaveMode2 = true; + + # Set sidebar icon size + NSTableViewDefaultSizeMode = 3; + + # Expand print panel by default + PMPrintingExpandedStateForPrint = true; + PMPrintingExpandedStateForPrint2 = true; + }; + + # Disable the “Are you sure you want to open this application?” dialog + system.defaults.LaunchServices.LSQuarantine = false; + + # Reduce Motion + system.defaults.universalaccess.reduceMotion = true; + + # Finder + system.defaults.finder = { + # Finder: show all filename extensions + AppleShowAllExtensions = true; + + # When performing a search, search the current folder by default + FXDefaultSearchScope = "SCcf"; + + # Disable the warning when changing a file extension + FXEnableExtensionChangeWarning = false; + + # Show path breadcrumbs in finder windows. + ShowPathbar = true; + + # Show status bar at bottom of finder windows with item/disk space stats. + ShowStatusBar = true; + + # Change the default finder view. “icnv” = Icon view, “Nlsv” = List view, “clmv” = Column View, “Flwv” = Gallery View + FXPreferredViewStyle = "clmv"; + }; + + # Magic Mouse + system.defaults.magicmouse.MouseButtonMode = "TwoButton"; + + # Dock + system.defaults.dock = { + # Automatically hide and show the Dock + autohide = true; + + # Remove the auto-hiding Dock delay + autohide-delay = 0.0; + + # Remove the animation when hiding/showing the Dock + autohide-time-modifier = 0.0; + + # Speed up Mission Control animations + expose-animation-duration = 0.1; + + # Don’t animate opening applications from the Dock + launchanim = false; + + # Change minimize/maximize window effect + mineffect = "scale"; + + # Minimize windows into their application’s icon + minimize-to-application = true; + + # Don’t automatically rearrange Spaces based on most recent use + mru-spaces = false; + + # Hide indicator lights for open applications in the Dock + show-process-indicators = true; + + # Don’t show recent applications in Dock + show-recents = false; + + # Make Dock icons of hidden applications translucent + showhidden = true; + + # Set the icon size of Dock items to 36 pixels + tilesize = 36; + + # Hot corners + wvous-br-corner = 10; # bottom right (Put display to sleep) + wvous-tl-corner = 4; # top left (Desktop) + wvous-tr-corner = 12; # top right (Mission Control) + + # Apps in the Dock + persistent-apps = [ + "/Applications/Things3.app" + "/Applications/Proton\ Mail.app" + "/System/Applications/Calendar.app" + "/Applications/WezTerm.app" + "/Applications/Arc.app" + "/Applications/Brave\ Browser.app" + "/System/Applications/Messages.app" + "/Applications/iA\ Writer.app" + "/Applications/Obsidian.app" + "/Applications/DEVONthink\ 3.app" + "/Applications/Eagle.app" + "/Applications/Spotify.app" + "/Applications/Anki.app" + "/Applications/Proton\ Pass.app" + "/System/Applications/System\ Settings.app" + ]; + }; + + # Trackpad, mouse, keyboard, Bluetooth accessories, and input + system.defaults.trackpad = { + # Whether to enable trackpad tap to click. + Clicking = true; + + # Whether to enable trackpad right click. + TrackpadRightClick = true; + + # Whether to enable tap-to-drag. + Dragging = true; + }; + + # Finder + system.activationScripts.postActivation.text = '' + # Show the ~/Library folder + chflags nohidden ~/Library + + # Show the /Volumes folder + sudo chflags nohidden /Volumes + ''; + + # Additional system configurations + system.defaults.NSGlobalDomain.AppleKeyboardUIMode = 3; + system.defaults.NSGlobalDomain.AppleFontSmoothing = 2; + + # Services services.skhd.enable = true; services.yabai.enable = true; } diff --git a/darwin/homebrew-common.nix b/darwin/homebrew-common.nix index 894b0be..abeaa87 100644 --- a/darwin/homebrew-common.nix +++ b/darwin/homebrew-common.nix @@ -74,6 +74,7 @@ "ogdesign-eagle" # Organise all your reference images in one place "ollama" # Get up and running with large language models locally "philips-hue-sync" # Control your smart light system + "pictogram" # Customise and maintain app icons "proton-drive" # Client for Proton Drive "proton-mail" # Client for Proton Mail and Proton Calendar "proton-pass" # Desktop client for Proton Pass diff --git a/hosts/mac-mini/configuration.nix b/hosts/mac-mini/configuration.nix index 6ffeccb..6b02ce1 100644 --- a/hosts/mac-mini/configuration.nix +++ b/hosts/mac-mini/configuration.nix @@ -1,4 +1,4 @@ -{ pkgs, config, ... }: +{ config, ... }: { imports = [ @@ -10,5 +10,10 @@ home = "/Users/kogakure"; }; + nixpkgs.hostPlatform = "aarch64-darwin"; + + # Screenshots + system.defaults.screencapture.location = "${config.users.users.kogakure.home}/Dropbox/Bilder/Screenshots"; + homebrew = import ./homebrew.nix; } diff --git a/setup/deno.sh b/scripts/deno.sh similarity index 100% rename from setup/deno.sh rename to scripts/deno.sh diff --git a/setup/golang.sh b/scripts/golang.sh similarity index 100% rename from setup/golang.sh rename to scripts/golang.sh diff --git a/setup/init.sh b/scripts/init.sh similarity index 67% rename from setup/init.sh rename to scripts/init.sh index 5860aaa..2cc10a6 100755 --- a/setup/init.sh +++ b/scripts/init.sh @@ -1,12 +1,8 @@ #!/bin/sh -echo "Setting up the Mac" +echo "Installing asdf plugins and versions" sudo -v -# Xcode Developer Tools -echo "Installing Xcode Developer Tools" -xcode-select --install - # Neovim echo "Installing Neovim" source ./neovim.sh @@ -38,7 +34,3 @@ source ./ruby.sh # Golang echo "Installing Go" source ./golang.sh - -# MacOS Default Settings -echo "Restoring default settings for MacOS" -source ./macos.sh diff --git a/setup/lua.sh b/scripts/lua.sh similarity index 100% rename from setup/lua.sh rename to scripts/lua.sh diff --git a/setup/neovim.sh b/scripts/neovim.sh similarity index 100% rename from setup/neovim.sh rename to scripts/neovim.sh diff --git a/setup/nodejs.sh b/scripts/nodejs.sh similarity index 100% rename from setup/nodejs.sh rename to scripts/nodejs.sh diff --git a/setup/python.sh b/scripts/python.sh similarity index 100% rename from setup/python.sh rename to scripts/python.sh diff --git a/setup/ruby.sh b/scripts/ruby.sh similarity index 100% rename from setup/ruby.sh rename to scripts/ruby.sh diff --git a/setup/rust.sh b/scripts/rust.sh similarity index 100% rename from setup/rust.sh rename to scripts/rust.sh diff --git a/setup/macos.sh b/setup/macos.sh deleted file mode 100644 index 92c4d2f..0000000 --- a/setup/macos.sh +++ /dev/null @@ -1,194 +0,0 @@ -#!/usr/bin/env bash - -# Inspired by https://mths.be/macos - -# Close any open System Preferences panes, to prevent them from overriding -# settings we’re about to change -osascript -e 'tell application "System Preferences" to quit' - -# Ask for the administrator password upfront -sudo -v - -# Keep-alive: update existing `sudo` time stamp until `macos.sh` has finished -while true; do - sudo -n true - sleep 60 - kill -0 "$$" || exit -done 2>/dev/null & - -############################################################################### -# General UI/UX # -############################################################################### - -# Set Dark Mode -defaults write -g AppleInterfaceStyle Dark - -# Set sidebar icon size -defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 3 - -# Expand save panel by default -defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true -defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true - -# Expand print panel by default -defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true -defaults write NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool true - -# Disable the “Are you sure you want to open this application?” dialog -defaults write com.apple.LaunchServices LSQuarantine -bool false - -# Disable automatic capitalization as it’s annoying when typing code -defaults write NSGlobalDomain NSAutomaticCapitalizationEnabled -bool false - -# Disable smart dashes as they’re annoying when typing code -defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false - -# Disable automatic period substitution as it’s annoying when typing code -defaults write NSGlobalDomain NSAutomaticPeriodSubstitutionEnabled -bool false - -# Disable smart quotes as they’re annoying when typing code -defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false - -# Disable auto-correct -defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false - -# Reduce Motion -defaults write com.apple.universalaccess reduceMotion -bool true - -# Menu Bar Size -defaults write NSGlobalDomain NSTitleBarSize 22 - -############################################################################### -# Trackpad, mouse, keyboard, Bluetooth accessories, and input # -############################################################################### - -# Set a blazingly fast keyboard repeat rate -defaults write NSGlobalDomain KeyRepeat -int 1 -defaults write NSGlobalDomain InitialKeyRepeat -int 10 - -# Set language and text formats -defaults write NSGlobalDomain AppleLanguages -array "en-DE" "de-DE" "ja-DE" -defaults write NSGlobalDomain AppleLocale -string "en_DE@currency=EUR" -defaults write NSGlobalDomain AppleMeasurementUnits -string "Centimeters" - -############################################################################### -# Screen # -############################################################################### - -# Save screenshots to the desktop -defaults write com.apple.screencapture location -string "${HOME}/Dropbox/Bilder/Screenshots" - -############################################################################### -# Finder # -############################################################################### - -# Set Desktop as the default location for new Finder windows -# For other paths, use `PfLo` and `file:///full/path/here/` -defaults write com.apple.finder NewWindowTarget -string "PfLo" -defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}/Downloads/" - -# Show/hide icons for hard drives, servers, and removable media on the desktop -defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool false -defaults write com.apple.finder ShowHardDrivesOnDesktop -bool false -defaults write com.apple.finder ShowMountedServersOnDesktop -bool false -defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true - -# Finder: show all filename extensions -defaults write NSGlobalDomain AppleShowAllExtensions -bool true - -# Finder: show status bar -defaults write com.apple.finder ShowStatusBar -bool true - -# Finder: show path bar -defaults write com.apple.finder ShowPathbar -bool true - -# Keep folders on top when sorting by name -defaults write com.apple.finder _FXSortFoldersFirst -bool true - -# When performing a search, search the current folder by default -defaults write com.apple.finder FXDefaultSearchScope -string "SCcf" - -# Disable the warning when changing a file extension -defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false - -# Enable spring loading for directories -defaults write NSGlobalDomain com.apple.springing.enabled -bool true - -# Remove the spring loading delay for directories -defaults write NSGlobalDomain com.apple.springing.delay -float 0.5 - -# Avoid creating .DS_Store files on network or USB volumes -defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true -defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true - -# Disable disk image verification -defaults write com.apple.frameworks.diskimages skip-verify -bool true -defaults write com.apple.frameworks.diskimages skip-verify-locked -bool true -defaults write com.apple.frameworks.diskimages skip-verify-remote -bool true - -# Automatically open a new Finder window when a volume is mounted -defaults write com.apple.frameworks.diskimages auto-open-ro-root -bool true -defaults write com.apple.frameworks.diskimages auto-open-rw-root -bool true -defaults write com.apple.finder OpenWindowForNewRemovableDisk -bool true - -# Show the ~/Library folder -chflags nohidden ~/Library - -# Show the /Volumes folder -sudo chflags nohidden /Volumes - -############################################################################### -# Dock, Dashboard, and hot corners # -############################################################################### - -# Set the icon size of Dock items to 36 pixels -defaults write com.apple.dock tilesize -int 36 - -# Change minimize/maximize window effect -defaults write com.apple.dock mineffect -string "scale" - -# Minimize windows into their application’s icon -defaults write com.apple.dock minimize-to-application -bool true - -# Disable spring loading for all Dock items -defaults write com.apple.dock enable-spring-load-actions-on-all-items -bool false - -# Hide indicator lights for open applications in the Dock -defaults write com.apple.dock show-process-indicators -bool true - -# Don’t animate opening applications from the Dock -defaults write com.apple.dock launchanim -bool false - -# Speed up Mission Control animations -defaults write com.apple.dock expose-animation-duration -float 0.1 - -# Don’t automatically rearrange Spaces based on most recent use -defaults write com.apple.dock mru-spaces -bool false - -# Remove the auto-hiding Dock delay -defaults write com.apple.dock autohide-delay -float 0 - -# Remove the animation when hiding/showing the Dock -defaults write com.apple.dock autohide-time-modifier -float 0 - -# Automatically hide and show the Dock -defaults write com.apple.dock autohide -bool true - -# Make Dock icons of hidden applications translucent -defaults write com.apple.dock showhidden -bool true - -# Don’t show recent applications in Dock -defaults write com.apple.dock show-recents -bool false - -############################################################################### -# Kill affected applications # -############################################################################### - -for app in "Dock" \ - "Finder" \ - "Messages" \ - "SystemUIServer"; do - killall "${app}" &>/dev/null -done - -echo "Done. Note that some of these changes require a logout/restart to take effect."