Fix nixos-option

In particular, it no longer produces an "infinite recursion" error
when run with no arguments.

Changed files
+22 -21
lib
nixos
lib
modules
installer
+1
lib/modules.nix
···
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 != [];
};
+3 -3
nixos/default.nix
···
modules = [ configuration ];
};
-
inherit (eval) config pkgs;
+
inherit (eval) pkgs;
# This is for `nixos-rebuild build-vm'.
vmConfig = (import ./lib/eval-config.nix {
···
in
{
-
inherit eval config;
+
inherit (eval) config options;
-
system = config.system.build.toplevel;
+
system = eval.config.system.build.toplevel;
vm = vmConfig.system.build.vm;
+5 -8
nixos/lib/eval-config.nix
···
# 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.
+13 -10
nixos/modules/installer/tools/nixos-option.sh
···
#! @shell@ -e
+
# FIXME: rewrite this in a more suitable language.
+
usage () {
exec man nixos-option
exit 1
···
}
evalAttr(){
-
local prefix=$1
-
local suffix=$2
-
local strict=$3
+
local prefix="$1"
+
local strict="$2"
+
local suffix="$3"
echo "(import <nixos> {}).$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 <nixos> {}).eval.options${option:+.$option}.$suffix" |
+
echo "(import <nixos> {}).options${option:+.$option}.$suffix" |
evalNix --strict
}
···
nixos = import <nixos> {};
nixpkgs = import <nixpkgs> {};
sources = builtins.map (f: f.source);
-
opt = reach nixos.eval.options;
+
opt = reach nixos.options;
cfg = reach nixos.config;
in
···
fi
if test "$(evalOpt "_type" 2> /dev/null)" = '"option"'; then
-
$value && evalCfg;
+
$value && evalCfg 1
if $desc; then
$value && echo;
···
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"; }