1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-04-09 10:42:53 +00:00

generalize system.defaults activation

This commit is contained in:
Daiderd Jordan 2016-12-13 23:05:10 +01:00
parent 1c38dd79db
commit 7a6ee11373
No known key found for this signature in database
GPG key ID: D02435D05B810C96

View file

@ -6,6 +6,23 @@ let
cfg = config.system.defaults;
writeValue = value:
if isBool value then "-bool ${if value then "YES" else "NO"}" else
if isInt value then "-int ${toString value}" else
if isString value then "-string '${value}'" else
throw "invalid value type";
writeDefault = domain: key: value:
"defaults write ${domain} '${key}' ${writeValue value}";
defaultsToList = domain: attrs: mapAttrsToList (writeDefault domain) (filterAttrs (n: v: v != null) attrs);
global = defaultsToList "-g" cfg.global;
dock = defaultsToList "com.apple.dock" cfg.dock;
finder = defaultsToList "com.apple.finder" cfg.finder;
trackpad = defaultsToList "com.apple.driver.AppleBluetoothMultitouch.trackpad" cfg.trackpad;
LaunchServices = defaultsToList "com.apple.LaunchServices" cfg.LaunchServices;
in
{
@ -21,17 +38,40 @@ in
default = null;
};
system.defaults.dock.autohide = mkOption {
type = types.nullOr types.bool;
default = null;
};
system.defaults.finder.AppleShowAllExtensions = mkOption {
type = types.nullOr types.bool;
default = null;
};
system.defaults.trackpad.Clicking = mkOption {
type = types.nullOr types.bool;
default = null;
};
system.defaults.LaunchServices.LSQuarantine = mkOption {
type = types.nullOr types.bool;
default = null;
};
};
config = {
system.activationScripts.defaults.text = ''
# Set defaults
echo "writing defaults..." >&2
'' + optionalString (cfg.global.InitialKeyRepeat != null) ''
defaults write -g InitialKeyRepeat -int ${toString cfg.global.InitialKeyRepeat}
'' + optionalString (cfg.global.KeyRepeat != null) ''
defaults write -g KeyRepeat -int ${toString cfg.global.KeyRepeat}
${concatStringsSep "\n" global}
${concatStringsSep "\n" dock}
${concatStringsSep "\n" finder}
${concatStringsSep "\n" trackpad}
${concatStringsSep "\n" LaunchServices}
'';
};
}