diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-03-25T18·58+0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-25T18·58+0100 |
commit | 5c05c238e60998b9fd276b3c4a39c860dc291200 (patch) | |
tree | 0291bf82b32516f682b438eafb0bd39047abe211 | |
parent | 63e7fc509628874bf60d9e436af387bfb1bc00a5 (diff) | |
parent | 514b3c7f8345cfcbbe166981214497ed9d93ae18 (diff) |
Merge pull request #1828 from zimbatm/isPath
Add isPath primop
-rw-r--r-- | doc/manual/expressions/builtins.xml | 8 | ||||
-rw-r--r-- | src/libexpr/primops.cc | 7 | ||||
-rw-r--r-- | tests/lang/eval-okay-types.nix | 2 |
3 files changed, 17 insertions, 0 deletions
diff --git a/doc/manual/expressions/builtins.xml b/doc/manual/expressions/builtins.xml index cefc8b78eebe..0fb5261b384c 100644 --- a/doc/manual/expressions/builtins.xml +++ b/doc/manual/expressions/builtins.xml @@ -861,6 +861,14 @@ x: x + 456</programlisting> </varlistentry> + <varlistentry><term><function>builtins.isPath</function> + <replaceable>e</replaceable></term> + + <listitem><para>Return <literal>true</literal> if + <replaceable>e</replaceable> evaluates to a path, and + <literal>false</literal> otherwise.</para></listitem> + + </varlistentry> <varlistentry xml:id='builtin-isNull'> <term><function>isNull</function> diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 6b0c55e72cd9..39073725e9c4 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -315,6 +315,12 @@ static void prim_isBool(EvalState & state, const Pos & pos, Value * * args, Valu mkBool(v, args[0]->type == tBool); } +/* Determine whether the argument is a path. */ +static void prim_isPath(EvalState & state, const Pos & pos, Value * * args, Value & v) +{ + state.forceValue(*args[0]); + mkBool(v, args[0]->type == tPath); +} struct CompareValues { @@ -2169,6 +2175,7 @@ void EvalState::createBaseEnv() addPrimOp("__isInt", 1, prim_isInt); addPrimOp("__isFloat", 1, prim_isFloat); addPrimOp("__isBool", 1, prim_isBool); + addPrimOp("__isPath", 1, prim_isPath); addPrimOp("__genericClosure", 1, prim_genericClosure); addPrimOp("abort", 1, prim_abort); addPrimOp("__addErrorContext", 2, prim_addErrorContext); diff --git a/tests/lang/eval-okay-types.nix b/tests/lang/eval-okay-types.nix index a34775f5e602..9b58be5d1dd4 100644 --- a/tests/lang/eval-okay-types.nix +++ b/tests/lang/eval-okay-types.nix @@ -20,6 +20,8 @@ with builtins; (isFloat (1 - 2.0)) (isBool (true && false)) (isBool null) + (isPath /nix/store) + (isPath ./.) (isAttrs { x = 123; }) (isAttrs null) (typeOf (3 * 4)) |