Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System defaults not applied properly nor globally #1207

Open
JanKleine opened this issue Dec 1, 2024 · 7 comments
Open

System defaults not applied properly nor globally #1207

JanKleine opened this issue Dec 1, 2024 · 7 comments

Comments

@JanKleine
Copy link

Hi,

I recently setup a new MacBook with nix-darwin as I wanted to give it a try for a while.

I noticed that the system.defaults... don't seem to be set properly nor globally (for all users). It's entirely possible that I made a mistake as I'm very new to this.

I have the following defaults:

system.defaults = {
    controlcenter.BatteryShowPercentage = true;
    finder.FXPreferredViewStyle = "Nlsv";
    screensaver.askForPassword = true;
    screensaver.askForPasswordDelay = 0;
    trackpad = {
        Clicking = true;
        TrackpadThreeFingerDrag = true;
    };
};

Firstly I noticed that trackpad.Clicking seems to work1, however in System Settings > Trackpad > Tap to click is still disabled. It is technically working I guess, but gives me the slightly uneasy feeling that settings are not being applied properly. The same applies to trackpad.TrackpadThreeFingerDrag and System Settings > Accessibility > Pointer Control > Trackpad Options... > Use trackpad for dragging.

controlcenter.BatteryShowPercentage on the other hand works just fine and is also reflected in the settings.

screensaver.askForPassword and screensaver.askForPasswordDelay don't seem to take affect at all, which is more of an issue, especially with these settings being security relevant. This seems to have been mentioned before in #908.

Finally, all these settings do not seem to work for another user on the system. I have the user listed under users.users, but even controlcenter.BatteryShowPercentage, which is working as expected for the user controlling nix-darwin, is not being applied.

Is this a bug or is there something wrong with my multi user setup? I'm happy to share more details if needed and appreciate any help!

Basic system infos:
MacBook Pro with M4 Pro
macOS: 15.1.1
nix-darwin: 6ab87b7

Footnotes

  1. It may be that it only worked after a restart. I don't quite remember, but there was something that only worked after a restart.

@Enzime
Copy link
Collaborator

Enzime commented Dec 2, 2024

Currently system.defaults maps one to one with Apple defaults however some options in System Settings actually map to multiple defaults. We should add a new nix-darwin option like hardware.trackpad.tapToClick which sets all the relevant defaults for you.

The easiest way to test is usually to run defaults read > before.txt, change the setting and then defaults read > after.txt and then check what the differences are, sometimes it might change system wide settings as well so you might need to check sudo defaults read as well.

We'll need to remove system.defaults.screensaver.askForPassword* and add new options to use sysadminctl to set them instead, see: mathiasbynens/dotfiles#922 (comment), similar to: https://github.com/LnL7/nix-darwin/blob/e30a3622b606dffc622305b4bbe1cfe37e78fa40/modules/power/sleep.nix

Currently we only manage defaults for the primary user (the user you run darwin-rebuild switch as), we have plans to fix this but we haven't started on it yet see #96

I don't have the time to work on any of the changes I've described, so feel free to make PRs and I'll review them

@bryanprimus
Copy link

bryanprimus commented Dec 26, 2024

i'm not sure this is the same issue but it is also happened to me

system.defaults = {
        dock.autohide = true # --> this is working;
	dock.persistent-apps = [
	  "${pkgs.arc-browser}/Applications/Arc.app" # --> this is working;
	];
	NSGlobalDomain."com.apple.swipescrolldirection" = false; # --> this is working;
	NSGlobalDomain.KeyRepeat = 2; # --> this is not working;
	NSGlobalDomain.AppleInterfaceStyle = "Dark"; # --> this is not working;
};

when i ran

defaults read NSGlobalDomain AppleInterfaceStyle

the result is Dark which is correct but the appearance is not updated to dark, and it is still resolve to Auto in the System Settings

I'm in the macOS 14.6.1 Sonoma

@nalzok
Copy link

nalzok commented Dec 26, 2024

For the record, system.defaults.trackpad.Clicking does not appear to work on macOS 15.2 (24C101): even with this option set to True, tapping does not trigger clicking behavior, and "Tap to click" is disabled. Note that toggling "Tap to click" in System Settings automatically changes the option for "Secondary Click", which is probably why it doesn't work.

Tap to click = False Tap to click = True

Moreover, the option "Look up & data detectors" now defaults to "Force click with One Finger" instead of "Tap with three Fingers", which IIRC is different from previous versions.

Ah forget about that. All I needed was to logout and login again. However, the options in System Settings are not updated when I set stuff like system.defaults.trackpad.Clicking (even after a reboot), which mean the actual behavior can be inconsistent with the options shown on the System Settings GUI.

@Samasaur1
Copy link
Contributor

@bryanprimus Are you sure that setting AppleInterfaceStyle does anything? It doesn't appear to when run manually on my Mac; I think it's only useful to read it to check whether or not you're in dark mode. e.g.:

defaults read -globalDomain AppleInterfaceStyle &> /dev/null && echo "In dark mode" || echo "In light mode"

@thislooksfun
Copy link

I can confirm that setting AppleInterfaceStyle does work, just not instantly. defaults write NSGlobalDomain AppleInterfaceStyle "Dark" and defaults delete NSGlobalDomain AppleInterfaceStyle both change the light/dark mode on next login. I have not yet found a way to apply the change immediately.

@Samasaur1
Copy link
Contributor

AppleScript?

osascript -e 'tell application "System Events" to tell appearance preferences to set dark mode to not dark mode'

@thislooksfun
Copy link

Yeah, AppleScript works, but I was hoping for a way that wouldn't require it and the associated Automation permission.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants