about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorNicolas B. Pierron <nicolas.b.pierron@gmail.com>2014-12-20 16:51:49 -0800
committerNicolas B. Pierron <nicolas.b.pierron@gmail.com>2014-12-20 16:51:49 -0800
commit91cc22e841354199d16f5f86fcaf3395eebf92c7 (patch)
treed9ee3fa75f265cd8d58800572af245cba10ade00 /nixos
parentc231506b5ad9c4609278204b0480c994d91333e2 (diff)
parentcd2f7ce9f9f10894c6d2a5995f06fb9d2a7f6795 (diff)
downloadnixlib-91cc22e841354199d16f5f86fcaf3395eebf92c7.tar
nixlib-91cc22e841354199d16f5f86fcaf3395eebf92c7.tar.gz
nixlib-91cc22e841354199d16f5f86fcaf3395eebf92c7.tar.bz2
nixlib-91cc22e841354199d16f5f86fcaf3395eebf92c7.tar.lz
nixlib-91cc22e841354199d16f5f86fcaf3395eebf92c7.tar.xz
nixlib-91cc22e841354199d16f5f86fcaf3395eebf92c7.tar.zst
nixlib-91cc22e841354199d16f5f86fcaf3395eebf92c7.zip
Merge pull request #5405 from nbp/nixos-options-derivation
nixos-option: Print the outPath of derivation for option values.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/installer/tools/nixos-option.sh35
1 files changed, 33 insertions, 2 deletions
diff --git a/nixos/modules/installer/tools/nixos-option.sh b/nixos/modules/installer/tools/nixos-option.sh
index 96d09c3a6058..4478059813d1 100644
--- a/nixos/modules/installer/tools/nixos-option.sh
+++ b/nixos/modules/installer/tools/nixos-option.sh
@@ -69,14 +69,45 @@ fi
 #############################
 
 evalNix(){
-  nix-instantiate - --eval-only "$@"
+  result=$(nix-instantiate - --eval-only "$@" 2>&1)
+  if test $? -eq 0; then
+      cat <<EOF
+$result
+EOF
+      return 0;
+  else
+      sed -n '/error/ { s/, at (string):[0-9]*:[0-9]*//; p; }' <<EOF
+$result
+EOF
+      return 1;
+  fi
 }
 
 evalAttr(){
   local prefix="$1"
   local strict="$2"
   local suffix="$3"
-  echo "(import <nixos> {}).$prefix${option:+.$option}${suffix:+.$suffix}" | evalNix ${strict:+--strict}
+
+  # If strict is set, then set it to "true".
+  test -n "$strict" && strict=true
+
+  evalNix ${strict:+--strict} <<EOF
+let
+  reach = attrs: attrs${option:+.$option}${suffix:+.$suffix};
+  nixos = import <nixos> {};
+  nixpkgs = import <nixpkgs> {};
+  strict = ${strict:-false};
+  cleanOutput = x: with nixpkgs.lib;
+    if isDerivation x then x.outPath
+    else if isFunction x then "<CODE>"
+    else if strict then
+      if isAttrs x then mapAttrs (n: cleanOutput) x
+      else if isList x then map cleanOutput x
+      else x
+    else x;
+in
+  cleanOutput (reach nixos.$prefix)
+EOF
 }
 
 evalOpt(){