Skip to content

Commit

Permalink
nix-store: read paths from standard input
Browse files Browse the repository at this point in the history
Resolves NixOS#7437 for new `nix-store` by adding a `--stdin` flag.
  • Loading branch information
nrdxp committed Feb 28, 2023
1 parent 269caa5 commit df64305
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/manual/src/command-ref/nix-store.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ have an effect.
created by sequentially numbering symlinks beyond the first one
(e.g., `foo`, `foo-2`, `foo-3`, and so on).

- <span id="opt-stdin">[`--stdin`](#opt-stdin)</span>

Read *paths…* from the standard input.
Useful for chaining nix-store commands.

# Operation `--realise`

## Synopsis
Expand Down
10 changes: 10 additions & 0 deletions src/nix-store/nix-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ static int main_nix_store(int argc, char * * argv)
{
Strings opFlags, opArgs;
Operation op = 0;
bool readFromStdIn;

parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
Operation oldOp = op;
Expand Down Expand Up @@ -1078,6 +1079,8 @@ static int main_nix_store(int argc, char * * argv)
op = opGenerateBinaryCacheKey;
else if (*arg == "--add-root")
gcRoot = absPath(getArg(*arg, arg, end));
else if (*arg == "--stdin" && !isatty(STDIN_FILENO))
readFromStdIn = true;
else if (*arg == "--indirect")
;
else if (*arg == "--no-output")
Expand All @@ -1090,6 +1093,13 @@ static int main_nix_store(int argc, char * * argv)
else
opArgs.push_back(*arg);

if (readFromStdIn && op != opImport && op != opRestore && op != opServe) {
std::string word;
while (std::cin >> word) {
opArgs.emplace_back(std::move(word));
};
}

if (oldOp && oldOp != op)
throw UsageError("only one operation may be specified");

Expand Down

0 comments on commit df64305

Please sign in to comment.