From 7a6ee11373e37dc425a0a4552e9b6254a432358c Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Tue, 13 Dec 2016 23:05:10 +0100 Subject: [PATCH] generalize system.defaults activation --- modules/system/defaults/default.nix | 48 ++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/modules/system/defaults/default.nix b/modules/system/defaults/default.nix index 7cfa041..6d472fe 100644 --- a/modules/system/defaults/default.nix +++ b/modules/system/defaults/default.nix @@ -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} ''; + }; }