git.iko.soy/typeable/nixpkgs
on master help sign in
nixos-option: don't abort with shell failures if options are not existant

`nixos-option` basically handles two cases: the given option is either a valid option defined using `mkOption` or an attribute set which contains a set of options. If none of the above cases is valid, `$1` is invalid. Unfortunatley the script interpreted invalid options as an attribute set which rendered shell failures when trying to evaluate the arguments. First of all, `if names=$(attrNames ...)` resulted in `<PRIMOP>` as `attrNames` simply evaluated `builtins.attrNames $result` which results in a non-applied function with `$result` being empty. Trying to map over this string using `nixMap` while applying `escapeQuotes` causes the bash error as `eval echo "<PRIMOP>"` is invalid syntax. Explicitly checking if `$result' contains a value (do we have an attribute set?) and otherwise returning a warning and asking if $option exists fixes the problem. Fixes #48060

commit76cc15a3640940aa5866a3fc573e8089f6b336c9 authorMaximilian Bosch <maximilian@mbosch.me> dateWed 10 Oct 2018, 13:19 (8 years ago) parentfc84778
1 file changed+3−3
nixos/modules/installer/tools/nixos-option.sh+3−3
nixos/modules/installer/tools/nixos-option.sh+3−3
@@ -314,13 +314,13 @@ else
314314 # echo 1>&2 "Warning: This value is not an option."
315315
316316 result=$(evalCfg "")
317− if names=$(attrNames "$result" 2> /dev/null); then
317+ if [ ! -z "$result" ]; then
318+ names=$(attrNames "$result" 2> /dev/null)
318319 echo 1>&2 "This attribute set contains:"
319320 escapeQuotes () { eval echo "$1"; }
320321 nixMap escapeQuotes "$names"
321322 else
322− echo 1>&2 "An error occurred while looking for attribute names."
323− echo $result
323+ echo 1>&2 "An error occurred while looking for attribute names. Are you sure that \`$option' exists?"
324324 fi
325325fi
326326