Skip to content

Implement --raw for nix-instantiate --eval#9361

Closed
infinisil wants to merge 1 commit intoNixOS:masterfrom
tweag:nix-instantiate-raw
Closed

Implement --raw for nix-instantiate --eval#9361
infinisil wants to merge 1 commit intoNixOS:masterfrom
tweag:nix-instantiate-raw

Conversation

@infinisil
Copy link
Member

@infinisil infinisil commented Nov 16, 2023

Motivation

For ages now I've been doing hacks like

nix-instantiate --eval <something> | tr -d \"
# Or
nix-instantiate --eval <something> | jq -r .

to get to the raw string content in the stable CLI.

Today I've had enough and went on to implement --raw within like 10 minutes and only a single compilation error.

Context

nix eval already supports --raw.

Implements --raw for nix-instantiate:

$ nix-instantiate --eval --raw --expr '"hello"'
hello

Not yet documented or tested.

On one hand the Nix team might be inclined to reject this because it changes the old CLI when you're trying to focus on the new one.

On the other hand, this is a 6 line change..

Priorities

Add 👍 to pull requests you find important.

@infinisil infinisil added the cli The old and/or new command line interface label Nov 16, 2023
@Ericson2314
Copy link
Member

This seems fine to me.

On one hand the Nix team might be inclined to reject this because it changes the old CLI when you're trying to focus on the new one.

I think while we shouldn't prioritize these things, if someone is willing to put in the work we shouldn't stop them either.

@roberth
Copy link
Member

roberth commented Nov 17, 2023

I agree with John, but also I would use this.

std::cout << std::endl;
} else if (output == okRaw) {
std::cout << *state.coerceToString(noPos, vRes, context, "while generating the nix-instantiate output");
std::cout << std::endl;
Copy link
Member

Choose a reason for hiding this comment

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

nix eval --raw is even more raw, by not adding a trailing newline.

            writeFull(STDOUT_FILENO, *state->coerceToString(noPos, *v, context, "while generating the eval command output"));

I think in both commands, we should make the extra newline dependent on whether stdout is a tty, probably as a general rule to be implemented in the proposed (elsewhere) function that factors out the stopProgressBar() + writeFull(STDOUT... combination.

Copy link
Member

Choose a reason for hiding this comment

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

Also I see no reason why we couldn't stop the progress bar in the old CLI.
If we don't have one, stopping it should just be a no-op.

Copy link
Member

Choose a reason for hiding this comment

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

Fwiw: There's a logger->pause() (and a corresponding logger->resume() method that's marginally more generic than stopProgressBar (well, in practice it does the same thing, but it's more future-proof).

@roberth
Copy link
Member

roberth commented Nov 17, 2023

See, now we're even discussing the new CLI, which actually is a priority.

@roberth
Copy link
Member

roberth commented May 20, 2024

This would improve the documentation as well

@infinisil are you still interested in completing this PR?

@infinisil
Copy link
Member Author

Interested yes, but not sufficient availability right now :)

I think this would be a great to label/advertise as a first good issue :)

@not-my-profile
Copy link
Contributor

As discussed in #dev:nixos.org I went ahead and picked this up in #12119.

@infinisil
Copy link
Member Author

@not-my-profile Thank you! ❤️

@infinisil infinisil closed this Dec 31, 2024
@infinisil infinisil deleted the nix-instantiate-raw branch December 31, 2024 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli The old and/or new command line interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants