From 85d12028ad4596e8de8152f9bfe49fff72c188da Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 24 Jul 2017 20:44:58 +0200 Subject: [PATCH] htop: use types.coercedTo (cherry picked from commit 1d24e96074ac8c4c787c556fc3fa0fd7ff4a25ca) --- modules/programs/htop.nix | 46 ++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/modules/programs/htop.nix b/modules/programs/htop.nix index b0f1a237d..10235ccda 100644 --- a/modules/programs/htop.nix +++ b/modules/programs/htop.nix @@ -87,28 +87,24 @@ let "CPU(4)" = 1; }; - singleMeterType = types.either (types.enum (attrNames meters)) (types.submodule { - options = { - kind = mkOption { - type = types.enum (attrNames meters); - example = "AllCPUs"; - description = "What kind of meter."; + singleMeterType = types.coercedTo + (types.enum (attrNames meters)) + (m: { kind = m; mode = meters.${m}; }) + (types.submodule { + options = { + kind = mkOption { + type = types.enum (attrNames meters); + example = "AllCPUs"; + description = "What kind of meter."; + }; + + mode = mkOption { + type = types.enum [ 1 2 3 4 ]; + example = 2; + description = "Which mode the meter should use, one of 1(Bar) 2(Text) 3(Graph) 4(LED)."; + }; }; - - mode = mkOption { - type = types.enum [ 1 2 3 4 ]; - example = 2; - description = "Which mode the meter should use, one of 1(Bar) 2(Text) 3(Graph) 4(LED)."; - }; - }; - }); - - # Converts the meter to an attribute set if it isn't already - meterStandard = m: if builtins.isString m then { - kind = m; - mode = meters.${m}; - } else m; - + }); meterType = types.submodule { options = { @@ -295,10 +291,10 @@ in home.packages = [ pkgs.htop ]; home.file.".config/htop/htoprc".text = let - leftMeters = map (m: (meterStandard m).kind) cfg.meters.left; - leftModes = map (m: (meterStandard m).mode) cfg.meters.left; - rightMeters = map (m: (meterStandard m).kind) cfg.meters.right; - rightModes = map (m: (meterStandard m).mode) cfg.meters.right; + leftMeters = map (m: m.kind) cfg.meters.left; + leftModes = map (m: m.mode) cfg.meters.left; + rightMeters = map (m: m.kind) cfg.meters.right; + rightModes = map (m: m.mode) cfg.meters.right; in '' # This file is regenerated by home-manager # when options are changed in the config