Skip to content

Commit

Permalink
Document fromTOML, hasContext and getContext builtins
Browse files Browse the repository at this point in the history
Until now, these functions were completely missing in the Nix manual.
  • Loading branch information
wentasah committed Jun 13, 2023
1 parent 8ec1ba0 commit 6c164d6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
24 changes: 22 additions & 2 deletions src/libexpr/primops/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ static void prim_hasContext(EvalState & state, const PosIdx pos, Value * * args,

static RegisterPrimOp primop_hasContext({
.name = "__hasContext",
.arity = 1,
.args = {"s"},
.doc = R"(
Return `true` if string *s* has a non-empty context. The
context can be obtained with
[`getContext`](#builtins-getContext).
)",
.fun = prim_hasContext
});

Expand Down Expand Up @@ -133,7 +138,22 @@ static void prim_getContext(EvalState & state, const PosIdx pos, Value * * args,

static RegisterPrimOp primop_getContext({
.name = "__getContext",
.arity = 1,
.args = {"s"},
.doc = R"(
Return the context associated with string *s*.
For example,
```nix
builtins.getContext "X ${derivation { name = "a"; builder = "b"; system = "c"; }}"
```
evaluates to
```
{ "/nix/store/arhvjaf6zmlyn8vh8fgn55rpwnxq0n7l-a.drv" = { outputs = [ "out" ]; }; }
```
)",
.fun = prim_getContext
});

Expand Down
16 changes: 15 additions & 1 deletion src/libexpr/primops/fromTOML.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,21 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value * * args, V

static RegisterPrimOp primop_fromTOML({
.name = "fromTOML",
.arity = 1,
.args = {"e"},
.doc = R"(
Convert a TOML string to a Nix value. For example,
```nix
builtins.fromTOML ''
x=1
s="a"
[table]
y=2
''
```
returns the value `{ s = "a"; table = { y = 2; }; x = 1; }`.
)",
.fun = prim_fromTOML
});

Expand Down

0 comments on commit 6c164d6

Please sign in to comment.