diff --git a/lib/modules.nix b/lib/modules.nix index d2b747339449..1163274e6bf6 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -160,6 +160,7 @@ rec { value = (opt.apply or id) merged; in opt // { value = addErrorContext "while evaluating the option `${showOption loc}':" value; + files = map (def: def.file) defs; definitions = map (def: def.value) defsFinal; isDefined = defsFinal != []; }; diff --git a/nixos/default.nix b/nixos/default.nix index 88f82a824822..5d69b79e13a6 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -9,7 +9,7 @@ let modules = [ configuration ]; }; - inherit (eval) config pkgs; + inherit (eval) pkgs; # This is for `nixos-rebuild build-vm'. vmConfig = (import ./lib/eval-config.nix { @@ -30,9 +30,9 @@ let in { - inherit eval config; + inherit (eval) config options; - system = config.system.build.toplevel; + system = eval.config.system.build.toplevel; vm = vmConfig.system.build.vm; diff --git a/nixos/lib/eval-config.nix b/nixos/lib/eval-config.nix index 5d487b91afb2..ece78691a848 100644 --- a/nixos/lib/eval-config.nix +++ b/nixos/lib/eval-config.nix @@ -16,14 +16,11 @@ rec { # Merge the option definitions in all modules, forming the full # system configuration. - systemModule = - pkgs.lib.evalModules { - modules = modules ++ baseModules; - args = extraArgs; - inherit check; - }; - - config = systemModule.config; + inherit (pkgs.lib.evalModules { + modules = modules ++ baseModules; + args = extraArgs; + inherit check; + }) config options; # These are the extra arguments passed to every module. In # particular, Nixpkgs is passed through the "pkgs" argument. diff --git a/nixos/modules/installer/tools/nixos-option.sh b/nixos/modules/installer/tools/nixos-option.sh index 69dd513f95c0..60cee2519da0 100644 --- a/nixos/modules/installer/tools/nixos-option.sh +++ b/nixos/modules/installer/tools/nixos-option.sh @@ -1,5 +1,7 @@ #! @shell@ -e +# FIXME: rewrite this in a more suitable language. + usage () { exec man nixos-option exit 1 @@ -90,24 +92,25 @@ evalNix(){ } evalAttr(){ - local prefix=$1 - local suffix=$2 - local strict=$3 + local prefix="$1" + local strict="$2" + local suffix="$3" echo "(import {}).$prefix${option:+.$option}${suffix:+.$suffix}" | evalNix ${strict:+--strict} } evalOpt(){ - evalAttr "eval.options" "$@" + evalAttr "options" "" "$@" } evalCfg(){ - evalAttr "config" "$@" + local strict="$1" + evalAttr "config" "$strict" } findSources(){ local suffix=$1 - echo "builtins.map (f: f.source) (import {}).eval.options${option:+.$option}.$suffix" | + echo "(import {}).options${option:+.$option}.$suffix" | evalNix --strict } @@ -143,7 +146,7 @@ let nixos = import {}; nixpkgs = import {}; sources = builtins.map (f: f.source); - opt = reach nixos.eval.options; + opt = reach nixos.options; cfg = reach nixos.config; in @@ -186,7 +189,7 @@ EOF fi if test "$(evalOpt "_type" 2> /dev/null)" = '"option"'; then - $value && evalCfg; + $value && evalCfg 1 if $desc; then $value && echo; @@ -212,14 +215,14 @@ if test "$(evalOpt "_type" 2> /dev/null)" = '"option"'; then nixMap printPath "$(findSources "declarations")" echo "" echo "Defined by:" - nixMap printPath "$(findSources "definitions")" + nixMap printPath "$(findSources "files")" echo "" fi else # echo 1>&2 "Warning: This value is not an option." - result=$(evalCfg) + result=$(evalCfg "") if names=$(attrNames "$result" 2> /dev/null); then echo 1>&2 "This attribute set contains:" escapeQuotes () { eval echo "$1"; }