aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThéophane Hufschmitt <7226587+thufschmitt@users.noreply.github.com>2022-03-17 14:35:01 +0100
committerGitHub <noreply@github.com>2022-03-17 14:35:01 +0100
commit711705345716109749c59586bee62238cabff76c (patch)
treec41e134068adf95cf477b9e042b53390ef8af2db /src
parenta0b517de5796d9a82b18242ecc63f507869237b1 (diff)
parent4f8ad41d4eb2012f01cd09ad745e78c5b8d8bee6 (diff)
Merge pull request #6270 from Artturin/stdineval
nix: allow using --file - to read from stdin
Diffstat (limited to 'src')
-rw-r--r--src/libcmd/installables.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
index b7623d4ba..784117569 100644
--- a/src/libcmd/installables.cc
+++ b/src/libcmd/installables.cc
@@ -134,7 +134,9 @@ SourceExprCommand::SourceExprCommand()
addFlag({
.longName = "file",
.shortName = 'f',
- .description = "Interpret installables as attribute paths relative to the Nix expression stored in *file*.",
+ .description =
+ "Interpret installables as attribute paths relative to the Nix expression stored in *file*. "
+ "If *file* is the character -, then a Nix expression will be read from standard input.",
.category = installablesCategory,
.labels = {"file"},
.handler = {&file},
@@ -695,7 +697,10 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
auto state = getEvalState();
auto vFile = state->allocValue();
- if (file)
+ if (file == "-") {
+ auto e = state->parseStdin();
+ state->eval(e, *vFile);
+ } else if (file)
state->evalFile(lookupFileArg(*state, *file), *vFile);
else {
auto e = state->parseExprFromString(*expr, absPath("."));