From 66eed7681d707ecf0dd9fe2a22e2fe2846ee60ed Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Sun, 24 Apr 2011 15:30:25 +0000 Subject: [PATCH] nixos-option: Add xml output to reduce the effort in nixos-gui. svn path=/nixos/trunk/; revision=26950 --- modules/installer/tools/nixos-option.sh | 71 +++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/modules/installer/tools/nixos-option.sh b/modules/installer/tools/nixos-option.sh index b2a0958ed893..4b76f824c4c8 100644 --- a/modules/installer/tools/nixos-option.sh +++ b/modules/installer/tools/nixos-option.sh @@ -11,7 +11,7 @@ export NIXOS usage () { echo 1>&2 " -Usage: $0 [--install] [-v] [-d] [-l] OPTION_NAME +Usage: $0 [--install] [-v] [-d] [-l] [--xml] OPTION_NAME $0 [--install] This program is used to explore NixOS options by looking at their values or @@ -31,6 +31,8 @@ Options: description. -l | --lookup Display where the option is defined and where it is declared. + --xml Print an XML representation of the result. + Implies -vdl options. --help Show this message. Environment variables affecting $0: @@ -52,6 +54,7 @@ Environment variables affecting $0: desc=false defs=false value=false +xml=false install=false verbose=false @@ -84,6 +87,7 @@ for arg; do --description) desc=true;; --value) value=true;; --lookup) defs=true;; + --xml) xml=true;; --install) install=true;; --verbose) verbose=true;; --help) usage;; @@ -106,6 +110,12 @@ for arg; do fi done +if $xml; then + value=true + desc=true + defs=true +fi + # --install cannot be used with -d -v -l without option name. if $value || $desc || $defs && $install && test -z "$option"; then usage @@ -130,12 +140,16 @@ fi # Process the configuration # ############################# +evalNix(){ + nix-instantiate - --eval-only "$@" +} + evalAttr(){ local prefix=$1 local suffix=$2 local strict=$3 echo "(import $NIXOS {}).$prefix${option:+.$option}${suffix:+.$suffix}" | - nix-instantiate - --eval-only ${strict:+--strict} + evalNix ${strict:+--strict} } evalOpt(){ @@ -149,7 +163,7 @@ evalCfg(){ findSources(){ local suffix=$1 echo "builtins.map (f: f.source) (import $NIXOS {}).eval.options${option:+.$option}.$suffix" | - nix-instantiate - --eval-only --strict + evalNix --strict } if $install; then @@ -277,6 +291,57 @@ if $generate; then exit 0 fi; +# This dupplicate the work made below, but it is useful for processing the +# output of nixos-option with other tools such as nixos-gui. +if $xml; then + evalNix --xml --no-location < /dev/null)" = '"option"'; then $value && evalCfg;