summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorMalo Bourgon <mbourgon@gmail.com>2022-08-29 15:39:16 -0700
committerMalo Bourgon <mbourgon@gmail.com>2022-08-29 15:39:16 -0700
commit5fa362c32f7a20ee1fb4baf7f23dc5128da6affe (patch)
treefc666fb6e991a661b2e955c1454f7c53c74ecbbe /modules
parent157a3c3c4ea482317a4eb4ea2c41db4f16c82420 (diff)
Transition to using native floats
Diffstat (limited to 'modules')
-rw-r--r--modules/nix/default.nix2
-rw-r--r--modules/system/defaults-write.nix13
-rw-r--r--modules/system/defaults/NSGlobalDomain.nix25
-rw-r--r--modules/system/defaults/dock.nix23
4 files changed, 29 insertions, 34 deletions
diff --git a/modules/nix/default.nix b/modules/nix/default.nix
index 2588d3b..528c304 100644
--- a/modules/nix/default.nix
+++ b/modules/nix/default.nix
@@ -37,7 +37,7 @@ let
if v == null then ""
else if isInt v then toString v
else if isBool v then boolToString v
- else if isFloat v then floatToString v
+ else if isFloat v then strings.floatToString v
else if isList v then toString v
else if isDerivation v then toString v
else if builtins.isPath v then toString v
diff --git a/modules/system/defaults-write.nix b/modules/system/defaults-write.nix
index 37e6760..8a6cb6e 100644
--- a/modules/system/defaults-write.nix
+++ b/modules/system/defaults-write.nix
@@ -5,14 +5,12 @@ with lib;
let
cfg = config.system.defaults;
- isFloat = x: isString x && builtins.match "^[+-]?([0-9]*[.])?[0-9]+$" x != null;
-
boolValue = x: if x then "YES" else "NO";
writeValue = value:
if isBool value then "-bool ${boolValue value}" else
if isInt value then "-int ${toString value}" else
- if isFloat value then "-float ${toString value}" else
+ if isFloat value then "-float ${strings.floatToString value}" else
if isString value then "-string '${value}'" else
throw "invalid value type";
@@ -48,6 +46,15 @@ in
{
config = {
+ # Type used for `system.defaults.<domain>.*` options that previously accepted float values as a
+ # string.
+ lib.defaults.types.floatWithDeprecationError = types.float // {
+ check = x:
+ if isString x && builtins.match "^[+-]?([0-9]*[.])?[0-9]+$" x != null
+ then throw "Using strings for `system.defaults.<domain>.*' options of type float is no longer permitted, use native float values instead."
+ else types.float.check x;
+ };
+
system.activationScripts.defaults.text = mkIfAttrs [
alf
loginwindow
diff --git a/modules/system/defaults/NSGlobalDomain.nix b/modules/system/defaults/NSGlobalDomain.nix
index 023c06c..49a2a86 100644
--- a/modules/system/defaults/NSGlobalDomain.nix
+++ b/modules/system/defaults/NSGlobalDomain.nix
@@ -3,15 +3,8 @@
with lib;
let
- isFloat = x: isString x && builtins.match "^[+-]?([0-9]*[.])?[0-9]+$" x != null;
-
- float = mkOptionType {
- name = "float";
- description = "float";
- check = isFloat;
- merge = options.mergeOneOption;
- };
-
+ # Should only be used with options that previously used floats defined as strings.
+ inherit (config.lib.defaults.types) floatWithDeprecationError;
in {
options = {
@@ -208,9 +201,9 @@ in {
};
system.defaults.NSGlobalDomain.NSWindowResizeTime = mkOption {
- type = types.nullOr float;
+ type = types.nullOr floatWithDeprecationError;
default = null;
- example = "0.20";
+ example = 0.20;
description = ''
Sets the speed speed of window resizing. The default is given in the example.
'';
@@ -273,14 +266,16 @@ in {
};
system.defaults.NSGlobalDomain."com.apple.sound.beep.volume" = mkOption {
- type = types.nullOr float;
+ type = types.nullOr floatWithDeprecationError;
default = null;
description = ''
# Apple menu > System Preferences > Sound
Sets the beep/alert volume level from 0.000 (muted) to 1.000 (100% volume).
75% = 0.7788008
+
50% = 0.6065307
+
25% = 0.4723665
'';
};
@@ -312,7 +307,7 @@ in {
};
system.defaults.NSGlobalDomain."com.apple.trackpad.scaling" = mkOption {
- type = types.nullOr float;
+ type = types.nullOr floatWithDeprecationError;
default = null;
description = ''
Configures the trackpad tracking speed (0 to 3). The default is "1".
@@ -328,9 +323,9 @@ in {
};
system.defaults.NSGlobalDomain."com.apple.springing.delay" = mkOption {
- type = types.nullOr float;
+ type = types.nullOr floatWithDeprecationError;
default = null;
- example = "1.0";
+ example = 1.0;
description = ''
Set the spring loading delay for directories. The default is given in the example.
'';
diff --git a/modules/system/defaults/dock.nix b/modules/system/defaults/dock.nix
index 3156e90..ba62e7a 100644
--- a/modules/system/defaults/dock.nix
+++ b/modules/system/defaults/dock.nix
@@ -3,15 +3,8 @@
with lib;
let
- isFloat = x: isString x && builtins.match "^[+-]?([0-9]*[.])?[0-9]+$" x != null;
-
- float = mkOptionType {
- name = "float";
- description = "float";
- check = isFloat;
- merge = options.mergeOneOption;
- };
-
+ # Should only be used with options that previously used floats defined as strings.
+ inherit (config.lib.defaults.types) floatWithDeprecationError;
in {
options = {
@@ -32,18 +25,18 @@ in {
};
system.defaults.dock.autohide-delay = mkOption {
- type = types.nullOr float;
+ type = types.nullOr floatWithDeprecationError;
default = null;
- example = "0.24";
+ example = 0.24;
description = ''
Sets the speed of the autohide delay. The default is given in the example.
'';
};
system.defaults.dock.autohide-time-modifier = mkOption {
- type = types.nullOr float;
+ type = types.nullOr floatWithDeprecationError;
default = null;
- example = "1.0";
+ example = 1.0;
description = ''
Sets the speed of the animation when hiding/showing the Dock. The default is given in the example.
'';
@@ -66,9 +59,9 @@ in {
};
system.defaults.dock.expose-animation-duration = mkOption {
- type = types.nullOr float;
+ type = types.nullOr floatWithDeprecationError;
default = null;
- example = "1.0";
+ example = 1.0;
description = ''
Sets the speed of the Mission Control animations. The default is given in the example.
'';