From 76cc15a3640940aa5866a3fc573e8089f6b336c9 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Wed, 10 Oct 2018 13:19:52 +0200 Subject: [PATCH 1/2] 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 `` 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 ""` 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 --- nixos/modules/installer/tools/nixos-option.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nixos/modules/installer/tools/nixos-option.sh b/nixos/modules/installer/tools/nixos-option.sh index 327e3e6989f..76db778da27 100644 --- a/nixos/modules/installer/tools/nixos-option.sh +++ b/nixos/modules/installer/tools/nixos-option.sh @@ -314,13 +314,13 @@ else # echo 1>&2 "Warning: This value is not an option." result=$(evalCfg "") - if names=$(attrNames "$result" 2> /dev/null); then + if [ ! -z "$result" ]; then + names=$(attrNames "$result" 2> /dev/null) echo 1>&2 "This attribute set contains:" escapeQuotes () { eval echo "$1"; } nixMap escapeQuotes "$names" else - echo 1>&2 "An error occurred while looking for attribute names." - echo $result + echo 1>&2 "An error occurred while looking for attribute names. Are you sure that \`$option' exists?" fi fi From a866551226a255207ee0cf39827086dbb732f0db Mon Sep 17 00:00:00 2001 From: Danylo Hlynskyi Date: Thu, 24 Jan 2019 02:37:29 +0200 Subject: [PATCH 2/2] nixos-option: prune backtick from output It doesn't work good with double-click selection in terminal (it gets into selection buffer of some terminals) --- nixos/modules/installer/tools/nixos-option.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/installer/tools/nixos-option.sh b/nixos/modules/installer/tools/nixos-option.sh index 76db778da27..4560e9c7403 100644 --- a/nixos/modules/installer/tools/nixos-option.sh +++ b/nixos/modules/installer/tools/nixos-option.sh @@ -320,7 +320,7 @@ else escapeQuotes () { eval echo "$1"; } nixMap escapeQuotes "$names" else - echo 1>&2 "An error occurred while looking for attribute names. Are you sure that \`$option' exists?" + echo 1>&2 "An error occurred while looking for attribute names. Are you sure that '$option' exists?" fi fi