From 36dcabd7be0d18b2532bfe9d77ff3d9e7e006cd4 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Tue, 19 May 2009 23:06:56 +0000 Subject: [PATCH] Add support for require attribute with a filename as argument. svn path=/nixpkgs/trunk/; revision=15657 --- pkgs/lib/options.nix | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/pkgs/lib/options.nix b/pkgs/lib/options.nix index 9df5617aebc5..79374132911d 100644 --- a/pkgs/lib/options.nix +++ b/pkgs/lib/options.nix @@ -136,6 +136,16 @@ rec { notHandle = opts: {}; }; + + # Unfortunately this can also be a string. + isPath = x: !( + builtins.isFunction x + || builtins.isAttrs x + || builtins.isInt x + || builtins.isBool x + || builtins.isList x + ); + # Evaluate a list of option sets that would be merged with the # function "merge" which expects two arguments. The attribute named # "require" is used to imports option declarations and bindings. @@ -157,6 +167,10 @@ rec { else cfgSet1; + filenameHandler = cfg: + if isPath cfg then import cfg + else cfg; + # call configuration "files" with one of the existing convention. argumentHandler = cfg: let @@ -173,9 +187,10 @@ rec { else cfg0; preprocess = cfg0: - let cfg1 = argumentHandler cfg0; - cfg2 = noImportConditions cfg1; - in cfg2; + let cfg1 = filenameHandler cfg0; + cfg2 = argumentHandler cfg1; + cfg3 = noImportConditions cfg2; + in cfg3; getRequire = x: toList (getAttr ["require"] [] (preprocess x));