LnL7 / nix-darwin

nix modules for darwin
MIT License
3.25k stars 461 forks source link

System defaults not applied properly nor globally #1207

Open JanKleine opened 1 day ago

JanKleine commented 1 day ago

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 work[^1], 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: 6ab87b7c84d4ee873e937108c4ff80c015a40c7a

[^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 commented 1 day ago

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: https://github.com/mathiasbynens/dotfiles/issues/922#issuecomment-1322698371, 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