fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6cfg = config . targets . darwin ; 7 8mkActivationCmds = isLocal :settings : 9let 10toDefaultsFile = domain :attrs : 11pkgs . writeText " ${ domain } .plist" ( lib . generators . toPlist { } attrs ); 12 13cliFlags = lib . optionalString isLocal "-currentHost" ; 14 15toActivationCmd = domain :attrs : 16"$DRY_RUN_CMD /usr/bin/defaults ${ cliFlags } import ${ 17escapeShellArg domain 18} ${ toDefaultsFile domain attrs } " ; 19 20nonNullDefaults = 21mapAttrs ( domain :attrs :( filterAttrs ( n :v :v != null ) attrs )) 22settings ; 23 24writableDefaults = 25filterAttrs ( domain :attrs :attrs != { }) nonNullDefaults ; 26in mapAttrsToList toActivationCmd writableDefaults ; 27 28defaultsCmds = mkActivationCmds false cfg . defaults ; 29currentHostDefaultsCmds = mkActivationCmds true cfg . currentHostDefaults ; 30 31activationCmds = defaultsCmds ++ currentHostDefaultsCmds ; 32in { 33meta . maintainers = [ maintainers . midchildan ]; 34 35options . targets . darwin . defaults = mkOption { 36type = types . submodule ./opts-allhosts.nix ; 37default = { }; 38example = { 39"com.apple.desktopservices" = { 40DSDontWriteNetworkStores = true ; 41DSDontWriteUSBStores = true ; 42}; 43}; 44description = '' 45Set macOS user defaults. Values set to `null` are 46ignored. 47 48::: {.warning} 49Some settings might require a re-login to take effect. 50::: 51 52::: {.warning} 53Some settings are only read from 54{option}`targets.darwin.currentHostDefaults`. 55::: 56'' ; 57}; 58 59options . targets . darwin . currentHostDefaults = mkOption { 60type = types . submodule ./opts-currenthost.nix ; 61default = { }; 62example = { 63"com.apple.controlcenter" = { BatteryShowPercentage = true ; }; 64}; 65description = '' 66Set macOS user defaults. Unlike {option}`targets.darwin.defaults`, 67the preferences will only be applied to the currently logged-in host. This 68distinction is important for networked accounts. 69 70Values set to `null` are ignored. 71 72::: {.warning} 73Some settings might require a re-login to take effect. 74::: 75'' ; 76}; 77 78config = mkIf ( activationCmds != [ ]) { 79assertions = [ 80( hm . assertions . assertPlatform "targets.darwin.defaults" pkgs 81platforms . darwin ) 82]; 83 84warnings = let 85batteryOptionName = '' 86targets.darwin.currentHostDefaults."com.apple.controlcenter".BatteryShowPercentage'' ; 87batteryPercentage = 88attrByPath [ "com.apple.menuextra.battery" "ShowPercent" ] null 89cfg . defaults ; 90webkitDevExtras = attrByPath [ 91"com.apple.Safari" 92"com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled" 93] null cfg . defaults ; 94in optional ( batteryPercentage != null ) '' 95The option 'com.apple.menuextra.battery.ShowPercent' no longer works on 96macOS 11 and later. Instead, use ' ${ batteryOptionName } '. 97'' ++ optional ( webkitDevExtras != null ) '' 98The option 'com.apple.Safari.com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled' 99is no longer present in recent versions of Safari. 100'' ; 101 102home . activation . setDarwinDefaults = hm . dag . entryAfter [ "writeBoundary" ] '' 103$VERBOSE_ECHO "Configuring macOS user defaults" 104${ concatStringsSep "\n" activationCmds } 105'' ; 106}; 107}