Nix Darwin Quick Tip: Activate Your Preferences

Patrick Walsh
3 min readApr 28, 2023

This is for folks who are already familiar with Nix and using it on a Mac with the nix-darwin module. If you don’t know much about Nix but want to get some idea of why you should use it (or at least, why I use it), this is a better entry point for you:

And if you want to use Nix on a Mac, but don’t know how to get started, I put together a (lamentably long) getting started video that walks you through how to set it up, choices, and my opinionated recommendations about those setup choices:

But here’s something that’s always annoyed me — including in that walkthrough video. If you configure some of your MacOS preferences via nix-darwin and then activate your system, you’ll find that some of them don’t take effect until you logout or restart your system. So if you change the dock autohide setting or the mouse speed, it isn’t very gratifying at first.

But that can be fixed!

In your nix-darwin config, add this:

  system.activationScripts.postUserActivation.text = ''
# Following line should allow us to avoid a logout/login cycle
/System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u

After all of your system settings have been changed as you activate a system, this will tell the OS to check for new settings and apply them now instead of waiting for the next login.

I’m not sure if it works in all cases, but in my tests, it has been magic. And it makes experimenting with settings much easier.

Bonus Tip

And while we’re at it, here’s something else related to MacOS system preferences that I discovered recently: if nix-darwin doesn’t have a config setting you want, you don’t have to add an activation script with some sort of defaults write my.setting -bool true series of calls (I still have a couple of these, but only for dictionary values now). Instead, you can use the system.defaults.CustomUserPreferences key.

Here are some of the custom user preferences that I migrated to this style of organizing:

    system.defaults.CustomUserPreferences = {
NSGlobalDomain = {
# Add a context menu item for showing the Web Inspector in web views
WebKitDeveloperExtras = true;
"" = {
ShowExternalHardDrivesOnDesktop = true;
ShowHardDrivesOnDesktop = true;
ShowMountedServersOnDesktop = true;
ShowRemovableMediaOnDesktop = true;
_FXSortFoldersFirst = true;
# When performing a search, search the current folder by default
FXDefaultSearchScope = "SCcf";
"" = {
# Avoid creating .DS_Store files on network or USB volumes
DSDontWriteNetworkStores = true;
DSDontWriteUSBStores = true;
"" = {
# Require password immediately after sleep or screen saver begins
askForPassword = 1;
askForPasswordDelay = 0;
"" = {
location = "~/Desktop";
type = "png";
"" = {
# Privacy: don’t send search queries to Apple
UniversalSearchEnabled = false;
SuppressSearchSuggestions = true;
# Press Tab to highlight each item on a web page
WebKitTabToLinksPreferenceKey = true;
ShowFullURLInSmartSearchField = true;
# Prevent Safari from opening ‘safe’ files automatically after downloading
AutoOpenSafeDownloads = false;
ShowFavoritesBar = false;
IncludeInternalDebugMenu = true;
IncludeDevelopMenu = true;
WebKitDeveloperExtrasEnabledPreferenceKey = true;
WebContinuousSpellCheckingEnabled = true;
WebAutomaticSpellingCorrectionEnabled = false;
AutoFillFromAddressBook = false;
AutoFillCreditCardData = false;
AutoFillMiscellaneousForms = false;
WarnAboutFraudulentWebsites = true;
WebKitJavaEnabled = false;
WebKitJavaScriptCanOpenWindowsAutomatically = false;
"" = true;
"" = true;
"" = false;
"" = false;
"" = false;
"" = false;
"" = {
# Disable inline attachments (just show the icons)
DisableInlineAttachmentViewing = true;
"" = {
allowApplePersonalizedAdvertising = false;
"" = {
# Automatically quit printer app once the print jobs complete
"Quit When Finished" = true;
"" = {
AutomaticCheckEnabled = true;
# Check for software updates daily, not just once per week
ScheduleFrequency = 1;
# Download newly available updates in background
AutomaticDownload = 1;
# Install System data files & security updates
CriticalUpdateInstall = 1;
"".DoNotOfferNewDisksForBackup = true;
# Prevent Photos from opening automatically when devices are plugged in
"".disableHotPlug = true;
# Turn on app auto-update
"".AutoUpdate = true;



Patrick Walsh

Scholar, dreamer, creator, adventurer, hacker, leader and observer. Advocate for privacy and security. CEO IronCore Labs.