diff options
author | Marc Weber <marco-oweber@gmx.de> | 2013-03-13 15:05:30 +0100 |
---|---|---|
committer | Evgeny Egorochkin <phreedom@yandex.ru> | 2013-08-22 11:10:53 +0300 |
commit | 52204af457c30781b09accc91c5d18d045d674ea (patch) | |
tree | c37d7c95cae9b09279d509f4ce9d27d9ad9596fc /pkgs | |
parent | acd4dcde6328dbacd8bff817d589dec132dae45e (diff) | |
download | nixlib-52204af457c30781b09accc91c5d18d045d674ea.tar nixlib-52204af457c30781b09accc91c5d18d045d674ea.tar.gz nixlib-52204af457c30781b09accc91c5d18d045d674ea.tar.bz2 nixlib-52204af457c30781b09accc91c5d18d045d674ea.tar.lz nixlib-52204af457c30781b09accc91c5d18d045d674ea.tar.xz nixlib-52204af457c30781b09accc91c5d18d045d674ea.tar.zst nixlib-52204af457c30781b09accc91c5d18d045d674ea.zip |
Refactor: introduce isType reducing redundancy (trivial change)
Diffstat (limited to 'pkgs')
-rw-r--r-- | pkgs/lib/options.nix | 6 | ||||
-rw-r--r-- | pkgs/lib/properties.nix | 16 | ||||
-rw-r--r-- | pkgs/lib/systems.nix | 12 | ||||
-rw-r--r-- | pkgs/lib/types.nix | 3 |
4 files changed, 19 insertions, 18 deletions
diff --git a/pkgs/lib/options.nix b/pkgs/lib/options.nix index 5f04f1ca8fb4..f10b5831267d 100644 --- a/pkgs/lib/options.nix +++ b/pkgs/lib/options.nix @@ -11,10 +11,10 @@ with import ./properties.nix; rec { - inherit (lib) typeOf; + inherit (lib) isType; - isOption = attrs: (typeOf attrs) == "option"; + isOption = isType "option"; mkOption = attrs: attrs // { _type = "option"; # name (this is the name of the attributem it is automatically generated by the traversal) @@ -190,7 +190,7 @@ rec { defValue = builtins.getAttr defName defs; optValue = builtins.getAttr defName opts; in - if typeOf defValue == "option" + if isOption defValue then # `defValue' is an option. if hasAttr defName opts diff --git a/pkgs/lib/properties.nix b/pkgs/lib/properties.nix index eeac27ae70c7..22aa8d891d8a 100644 --- a/pkgs/lib/properties.nix +++ b/pkgs/lib/properties.nix @@ -11,13 +11,13 @@ with import ./attrsets.nix; rec { - inherit (lib) typeOf; + inherit (lib) isType; # Tell that nothing is defined. When properties are evaluated, this type # is used to remove an entry. Thus if your property evaluation semantic # implies that you have to mute the content of an attribute, then your # property should produce this value. - isNotdef = attrs: (typeOf attrs) == "notdef"; + isNotdef = isType "notdef"; mkNotdef = {_type = "notdef";}; # General property type, it has a property attribute and a content @@ -32,7 +32,7 @@ rec { # - onGlobalDelay: run on all copied properties. # - onEval: run on an evaluated property. # - onGlobalEval: run on a list of property stack on top of their values. - isProperty = attrs: (typeOf attrs) == "property"; + isProperty = isType "property"; mkProperty = p@{property, content, ...}: p // { _type = "property"; }; @@ -187,7 +187,7 @@ rec { # and interpreted by the underlying system using properties (modules). # Create a "Merge" property which only contains a condition. - isMerge = attrs: (typeOf attrs) == "merge"; + isMerge = isType "merge"; mkMerge = content: mkProperty { property = { _type = "merge"; @@ -204,7 +204,7 @@ rec { # is ignore. # Create a "If" property which only contains a condition. - isIf = attrs: (typeOf attrs) == "if"; + isIf = isType "if"; mkIf = condition: content: mkProperty { property = { _type = "if"; @@ -271,7 +271,7 @@ rec { # priorities between values. The default priority is 100. The lowest # priorities are kept. The template argument must reproduce the same # attribute set hierarchy to override leaves of the hierarchy. - isOverride = attrs: (typeOf attrs) == "override"; + isOverride = isType "override"; mkOverrideTemplate = priority: template: content: mkProperty { property = { _type = "override"; @@ -371,7 +371,7 @@ rec { # of the list used by the merge function. And the highest ranked # definition would be the last. Definitions which does not have any rank # value have the default rank of 100. - isOrder = attrs: (typeOf attrs) == "order"; + isOrder = isType "order"; mkOrder = rank: content: mkProperty { property = { _type = "order"; @@ -434,7 +434,7 @@ rec { # properties on top of the option definition is nice for user manipulation # but require to check if the content of the property is not another # property. Such testing implies to verify if this is an attribute set - # and if it possess the type 'property'. (see isProperty & typeOf) + # and if it possess the type 'property'. (see isProperty & typeOf/isType) # # To avoid strict evaluation of option definitions, 'mkFixStrictness' is # introduced. This property protects an option definition by replacing diff --git a/pkgs/lib/systems.nix b/pkgs/lib/systems.nix index 09d04042f1cf..02c26ba600a3 100644 --- a/pkgs/lib/systems.nix +++ b/pkgs/lib/systems.nix @@ -15,14 +15,14 @@ in rec { - isSignificantByte = x: typeOf x == "significant-byte"; + isSignificantByte = isType "significant-byte"; significantBytes = setTypes "significant-byte" { bigEndian = {}; littleEndian = {}; }; - isCpuType = x: typeOf x == "cpu-type" + isCpuType = isType "cpu-type" && elem x.bits [8 16 32 64 128] && (builtins.lessThan 8 x.bits -> isSignificantByte x.significantByte); @@ -37,7 +37,7 @@ rec { }; - isExecFormat = x: typeOf x == "exec-format"; + isExecFormat = isType "exec-format"; execFormats = setTypes "exec-format" { aout = {}; # a.out elf = {}; @@ -47,7 +47,7 @@ rec { }; - isKernel = x: typeOf x == "kernel"; + isKernel = isType "kernel"; kernels = with execFormats; setTypes "kernel" { cygwin = { execFormat = pe; }; @@ -61,7 +61,7 @@ rec { }; - isArchitecture = x: typeOf x == "architecture"; + isArchitecture = isType "architecture"; architectures = setTypes "architecture" { apple = {}; pc = {}; @@ -69,7 +69,7 @@ rec { }; - isSystem = x: typeOf x == "system" + isSystem = isType "system" && isCpuType x.cpu && isArchitecture x.arch && isKernel x.kernel; diff --git a/pkgs/lib/types.nix b/pkgs/lib/types.nix index 9dce885b1826..156d72ac5e73 100644 --- a/pkgs/lib/types.nix +++ b/pkgs/lib/types.nix @@ -10,6 +10,7 @@ with import ./trivial.nix; rec { + isType = type: x: (x._type or "") == type; hasType = x: isAttrs x && x ? _type; typeOf = x: x._type or ""; @@ -26,7 +27,7 @@ rec { # hasOptions (boolean: whatever this option contains an option set) # delayOnGlobalEval (boolean: should properties go through the evaluation of this option) # docPath (path concatenated to the option name contained in the option set) - isOptionType = attrs: typeOf attrs == "option-type"; + isOptionType = isType "option-type"; mkOptionType = { name , check ? (x: true) |