[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
07/376: Add constant ‘nixPath’
From: |
Ludovic Courtès |
Subject: |
07/376: Add constant ‘nixPath’ |
Date: |
Wed, 28 Jan 2015 22:03:40 +0000 |
civodul pushed a commit to tag 1.8
in repository guix.
commit a8edf185a9e1677088c8c30acc9d281c8350bca7
Author: Eelco Dolstra <address@hidden>
Date: Mon May 26 14:55:47 2014 +0200
Add constant ‘nixPath’
It contains the Nix expression search path as a list of { prefix, path
} sets, e.g.
[ { path = "/nix/var/nix/profiles/per-user/root/channels/nixos"; prefix =
""; }
{ path = "/etc/nixos/configuration.nix"; prefix = "nixos-config"; }
{ path = "/home/eelco/Dev/nix/inst/share/nix/corepkgs"; prefix = "nix";
}
]
---
src/libexpr/primops.cc | 11 +++++++++++
tests/lang.sh | 2 +-
tests/lang/eval-okay-search-path.nix | 9 ++++++++-
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 533ae37..e492ff6 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -1352,6 +1352,17 @@ void EvalState::createBaseEnv()
evalFile(path, v);
addConstant("derivation", v);
+ /* Add a value containing the current Nix expression search path. */
+ mkList(v, searchPath.size());
+ int n = 0;
+ for (auto & i : searchPath) {
+ Value * v2 = v.list.elems[n++] = allocValue();
+ mkAttrs(*v2, 2);
+ mkString(*allocAttr(*v2, symbols.create("path")), i.second);
+ mkString(*allocAttr(*v2, symbols.create("prefix")), i.first);
+ }
+ addConstant("nixPath", v);
+
/* Now that we've added all primops, sort the `builtins' set,
because attribute lookups expect it to be sorted. */
baseEnv.values[0]->attrs->sort();
diff --git a/tests/lang.sh b/tests/lang.sh
index bb3b9ca..7157a68 100644
--- a/tests/lang.sh
+++ b/tests/lang.sh
@@ -46,7 +46,7 @@ for i in lang/eval-okay-*.nix; do
if test -e lang/$i.flags; then
flags=$(cat lang/$i.flags)
fi
- if ! NIX_PATH=lang/dir3:lang/dir4_PATH nix-instantiate $flags --eval
--strict lang/$i.nix > lang/$i.out; then
+ if ! NIX_PATH=lang/dir3:lang/dir4 nix-instantiate $flags --eval
--strict lang/$i.nix > lang/$i.out; then
echo "FAIL: $i should evaluate"
fail=1
elif ! diff lang/$i.out lang/$i.exp; then
diff --git a/tests/lang/eval-okay-search-path.nix
b/tests/lang/eval-okay-search-path.nix
index 9b71150..c9ea768 100644
--- a/tests/lang/eval-okay-search-path.nix
+++ b/tests/lang/eval-okay-search-path.nix
@@ -1,3 +1,10 @@
-assert builtins.pathExists <nix/buildenv.nix>;
+with import ./lib.nix;
+with builtins;
+
+assert pathExists <nix/buildenv.nix>;
+
+assert length nixPath == 3;
+assert length (filter (x: x.prefix == "nix") nixPath) == 1;
+assert length (filter (x: baseNameOf x.path == "dir4") nixPath) == 1;
import <a.nix> + import <b.nix> + import <c.nix> + import <dir5/c.nix>
- 04/376: Ugly hack to allow --argstr values starting with a dash, (continued)
- 04/376: Ugly hack to allow --argstr values starting with a dash, Ludovic Courtès, 2015/01/28
- 06/376: Add primop ‘scopedImport’, Ludovic Courtès, 2015/01/28
- 08/376: Ensure that -I flags get included in nixPath, Ludovic Courtès, 2015/01/28
- 11/376: Rephrase @ operator description, Ludovic Courtès, 2015/01/28
- 12/376: dev-shell is a bash script, not sh, Ludovic Courtès, 2015/01/28
- 09/376: Make the Nix search path declarative, Ludovic Courtès, 2015/01/28
- 03/376: Disable parallel.sh test, Ludovic Courtès, 2015/01/28
- 10/376: Remove ExprBuiltin, Ludovic Courtès, 2015/01/28
- 02/376: nix-store -l: Fetch build logs from the Internet, Ludovic Courtès, 2015/01/28
- 13/376: nix-build: --add-root also takes 1 parameter, Ludovic Courtès, 2015/01/28
- 07/376: Add constant ‘nixPath’,
Ludovic Courtès <=
- 17/376: nix-env -qa --json: Generate valid JSON even if there are invalid meta attrs, Ludovic Courtès, 2015/01/28
- 14/376: Use std::unordered_set, Ludovic Courtès, 2015/01/28
- 15/376: Sort nixPath attributes, Ludovic Courtès, 2015/01/28
- 16/376: Fix test, Ludovic Courtès, 2015/01/28
- 21/376: Add autoloads, make code more concise & idiomatic, Ludovic Courtès, 2015/01/28
- 18/376: Print a warning when loading a large path into memory, Ludovic Courtès, 2015/01/28
- 19/376: Report daemon OOM better, Ludovic Courtès, 2015/01/28
- 22/376: Share code between scopedImport and import, Ludovic Courtès, 2015/01/28
- 28/376: Only add the importNative primop if the allow-arbitrary-code-during-evaluation option is true (default false), Ludovic Courtès, 2015/01/28
- 26/376: Don't use member initialisers, Ludovic Courtès, 2015/01/28