diff options
author | Marc Weber <marco-oweber@gmx.de> | 2009-05-24 10:57:41 +0000 |
---|---|---|
committer | Marc Weber <marco-oweber@gmx.de> | 2009-05-24 10:57:41 +0000 |
commit | f7f938a1d15277fa11a2cbf75fe9c7d4344f25c3 (patch) | |
tree | 7f0728120b23ae097a4259c62839037bd84aebad /pkgs/lib | |
parent | 62620f0411b4ada733ae4e701416997140053762 (diff) | |
download | nixpkgs-f7f938a1d15277fa11a2cbf75fe9c7d4344f25c3.tar nixpkgs-f7f938a1d15277fa11a2cbf75fe9c7d4344f25c3.tar.gz nixpkgs-f7f938a1d15277fa11a2cbf75fe9c7d4344f25c3.tar.bz2 nixpkgs-f7f938a1d15277fa11a2cbf75fe9c7d4344f25c3.tar.lz nixpkgs-f7f938a1d15277fa11a2cbf75fe9c7d4344f25c3.tar.xz nixpkgs-f7f938a1d15277fa11a2cbf75fe9c7d4344f25c3.tar.zst nixpkgs-f7f938a1d15277fa11a2cbf75fe9c7d4344f25c3.zip |
big breaking change: renaming lib.getAttr to lib.attrByPath
getAttr was ambiguous. It's also a builtin function fix svn path=/nixpkgs/trunk/; revision=15692
Diffstat (limited to 'pkgs/lib')
-rw-r--r-- | pkgs/lib/attrsets.nix | 15 | ||||
-rw-r--r-- | pkgs/lib/misc.nix | 8 | ||||
-rw-r--r-- | pkgs/lib/options.nix | 6 |
3 files changed, 16 insertions, 13 deletions
diff --git a/pkgs/lib/attrsets.nix b/pkgs/lib/attrsets.nix index 1348a15bdba..1d3cabe6f1b 100644 --- a/pkgs/lib/attrsets.nix +++ b/pkgs/lib/attrsets.nix @@ -12,21 +12,24 @@ rec { /* Return an attribute from nested attribute sets. For instance ["x" "y"] applied to some set e returns e.x.y, if it exists. The - default value is returned otherwise. !!! there is also - builtins.getAttr (is there a better name for this function?) - */ - getAttr = attrPath: default: e: + default value is returned otherwise. */ + attrByPath = attrPath: default: e: let attr = head attrPath; in if attrPath == [] then e else if builtins ? hasAttr && hasAttr attr e - then getAttr (tail attrPath) default (builtins.getAttr attr e) + then attrByPath (tail attrPath) default (builtins.getAttr attr e) else default; + # keep compatibility for some time. will be removed soon (the name getAttr + # should only be used for the builtins primop) + getAttr = a : b : c : builtins.trace "depreceated usage of lib.getAttr!" + (attrByPath a b c); + getAttrFromPath = attrPath: set: let errorMsg = "cannot find attribute `" + concatStringsSep "." attrPath + "'"; - in getAttr attrPath (abort errorMsg) set; + in attrByPath attrPath (abort errorMsg) set; /* Return the specified attributes from a set. diff --git a/pkgs/lib/misc.nix b/pkgs/lib/misc.nix index b8e49bad977..d515158c00a 100644 --- a/pkgs/lib/misc.nix +++ b/pkgs/lib/misc.nix @@ -111,7 +111,7 @@ rec { pairMap = innerPairMap []; - # shortcut for getAttr ["name"] default attrs + # shortcut for attrByPath ["name"] default attrs maybeAttr = name: default: attrs: if (__hasAttr name attrs) then (__getAttr name attrs) else default; @@ -131,14 +131,14 @@ rec { checkFlag = attrSet: name: if (name == "true") then true else if (name == "false") then false else - if (elem name (getAttr ["flags"] [] attrSet)) then true else - getAttr [name] false attrSet ; + if (elem name (attrByPath ["flags"] [] attrSet)) then true else + attrByPath [name] false attrSet ; # Input : attrSet, [ [name default] ... ], name # Output : its value or default. getValue = attrSet: argList: name: - ( getAttr [name] (if checkFlag attrSet name then true else + ( attrByPath [name] (if checkFlag attrSet name then true else if argList == [] then null else let x = builtins.head argList; in if (head x) == name then diff --git a/pkgs/lib/options.nix b/pkgs/lib/options.nix index bd42b1dcf34..2e867cf44d7 100644 --- a/pkgs/lib/options.nix +++ b/pkgs/lib/options.nix @@ -193,7 +193,7 @@ rec { cfg3 = noImportConditions cfg2; in cfg3; - getRequire = x: toList (getAttr ["require"] [] (preprocess x)); + getRequire = x: toList (attrByPath ["require"] [] (preprocess x)); getRecusiveRequire = x: fold (cfg: l: if isPath cfg then @@ -221,7 +221,7 @@ rec { lib.fix (fixOptionSetsFun merge pkgs opts); optionAttrSetToDocList = l: attrs: - if (getAttr ["_type"] "" attrs) == "option" then + if (attrByPath ["_type"] "" attrs) == "option" then [({ #inherit (attrs) description; description = if attrs ? description then attrs.description else @@ -582,4 +582,4 @@ rec { mkNotdef ) prioValList; -} \ No newline at end of file +} |