From c6267a8c9d4f69719ffa8117a899081e2746904f Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Fri, 18 Sep 2009 15:10:11 +0000 Subject: [PATCH] Add declarations and definitions to options. This allow you to retrieve the location of the definition with the defined value. Filter the source location for the documentation. svn path=/nixpkgs/trunk/; revision=17253 --- pkgs/lib/modules.nix | 13 +++++++++++++ pkgs/lib/options.nix | 3 +++ 2 files changed, 16 insertions(+) diff --git a/pkgs/lib/modules.nix b/pkgs/lib/modules.nix index 10667dc3ade3..d9b9d3b54c1f 100644 --- a/pkgs/lib/modules.nix +++ b/pkgs/lib/modules.nix @@ -207,6 +207,19 @@ rec { addOptionMakeUp { name = addName name; recurseInto = recurseForOption; } (mergeOptionDecls decls) + // { + declarations = + map (m: { + source = m.key; + value = m.options; + }) (declarationsOf name); + + definitions = + map (m: { + source = m.key; + value = m.config; + }) (definitionsOf name); + } else if all isAttrs values then (recurseInto name modules).options else diff --git a/pkgs/lib/options.nix b/pkgs/lib/options.nix index 6aad285b7ac7..06d4fad8a325 100644 --- a/pkgs/lib/options.nix +++ b/pkgs/lib/options.nix @@ -240,6 +240,9 @@ rec { inherit (opt) name; description = if opt ? description then opt.description else throw "Option ${opt.name}: No description."; + + declarations = map (x: toString x.source) opt.declarations; + definitions = map (x: toString x.source) opt.definitions; } // (if opt ? example then {inherit(opt) example;} else {}) // (if opt ? default then {inherit(opt) default;} else {});