Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix: allow using --file - to read from stdin #2583

Closed
wants to merge 3 commits into from

Conversation

LnL7
Copy link
Member

@LnL7 LnL7 commented Dec 14, 2018

Brings the nix-instantiate - functionality to all the new nix commands that take the --file argument.

$ echo '{ foo = 1 + 1; }' | nix eval -f - foo
2

Copy link
Member

@dtzWill dtzWill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits while reading through, although in the end I think are out of scope for this PR. Sorry for the noise, but leaving in case helpful or folks want to discuss :). Will 'resolve' if seem less suitable by the end.

Only other suggestion would be to add a test or three for this welcome new functionality! 👍

addErrorPrefix(e, "while evaluating %1%:\n", "<stdin>");
throw;
}
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new indent level perhaps could be avoided with an early return? Suggesting to avoid noise it causes, not sure what general preference on that point is stylistically.

Concretely, perhaps drop the else { } and add a return at the end of the if {} or perhaps return eval(e, v) within the try {}?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what style is preferred, happy to change it if desired

src/libexpr/eval.cc Outdated Show resolved Hide resolved
src/libexpr/eval.cc Outdated Show resolved Hide resolved

FileEvalCache::iterator i;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-existing problem, but while looking through this... declaring these temporaries in the conditional seems to solve obvious scoping problems currently resolved by using variable names like path2 for temporaries later in the sequence... depending on auto preferences it'd look like this:

(EDIT: just kidding, looks like a clean solution for this requires c++17 maybe? (if (auto i = fileEvalCache.find(path); i != fileEvalCache.end())))

src/libexpr/eval.cc Outdated Show resolved Hide resolved
src/libexpr/eval.cc Outdated Show resolved Hide resolved
@dtzWill
Copy link
Member

dtzWill commented Dec 15, 2018

(I can't mark them resolved since they're comments! D'oh. Sorry about that :))

LnL7 added 2 commits July 2, 2019 00:15
Brings the `nix-instantiate -` functionality to all the new nix
commands that take the --file argument.

	$ echo '{ foo = 1 + 1; }' | nix eval -f - foo
	2
@LnL7
Copy link
Member Author

LnL7 commented Jul 2, 2019

@dtzWill I dismissed some of the comments, most of them where about existing code that I just indented.

src/libexpr/eval.cc Outdated Show resolved Hide resolved
Reading from stdin is only allowed for specific cli arguments,
make sure this isn't accidentally possible in expressions.
@stale
Copy link

stale bot commented Feb 13, 2021

I marked this as stale due to inactivity. → More info

@Artturin
Copy link
Member

#6270

@stale stale bot removed the stale label Mar 16, 2022
@Artturin
Copy link
Member

can be closed

@Artturin Artturin closed this May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants