Skip to content

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

Merged
mergify[bot] merged 2 commits intoNixOS:masterfrom
not-my-profile:nix-instantiate-raw
Dec 31, 2024
Merged

Implement --raw for nix-instantiate --eval#12119
mergify[bot] merged 2 commits intoNixOS:masterfrom
not-my-profile:nix-instantiate-raw

Conversation

@not-my-profile
Copy link
Contributor

Motivation

The experimental nix eval command already supports a --raw flag.
This commit implements the same flag for the stable nix-instantiate command.

Until now instructions and scripts that didn't want to rely on experimental
features had to use workarounds such as:

nix-instantiate --eval <something> | tr -d \"

(which also undesirably also removes double quotation marks within the string), or

nix-instantiate --eval <something> | jq -j

(which undesirably depends on another package).

Context

Continuation of #9361.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@github-actions github-actions bot added documentation with-tests Issues related to testing. PRs with tests have some priority labels Dec 31, 2024
@not-my-profile not-my-profile force-pushed the nix-instantiate-raw branch 2 times, most recently from e21f5e4 to 945098b Compare December 31, 2024 13:28
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

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

Document the newline behavior, then lgtm!

if (output == okXML)
if (output == okRaw)
std::cout << *state.coerceToString(noPos, vRes, context, "while generating the nix-instantiate output");
// We intentionally don't output a newline here. The default PS1 for Bash in NixOS starts with a newline
Copy link
Member

Choose a reason for hiding this comment

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

newline

This should be documented in the manual, perhaps without the reasoning.

Copy link
Member

Choose a reason for hiding this comment

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

idea (no action required)
--lines to allow multiple arguments and stream them to stdout, each on their own line. This would always add a newline, so --raw --lines would output a line. Perhaps also implicitly flattening lists as well, printing a line for each item.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mentioned the absence of a trailing newline in the manual.

@roberth
Copy link
Member

roberth commented Dec 31, 2024

@mergify queue

@mergify
Copy link
Contributor

mergify bot commented Dec 31, 2024

queue

✅ The pull request has been merged automatically

Details

The pull request has been merged automatically at 18f0770

@not-my-profile
Copy link
Contributor Author

I think the CI workflow is still awaiting approval.

@edolstra
Copy link
Member

I'm not super in favor of adding functionality to the legacy CLI that already exists in the new CLI. It does add a bunch of (essentially superfluous) code that we'll need to maintain indefinitely.

@roberth
Copy link
Member

roberth commented Dec 31, 2024

I hear you. Until we have stabilized the new CLI, users will have unmet needs on the old CLI for use in Nixpkgs etc, which rightfully has a policy of avoiding the experimental CLI. This allows us to apply learned insights to the new CLI without as much risk.
I agree for things like this which should arguably be implemented for the new CLI only. Stable CLI users can achieve essentially the same result with concatStringsSep and such. The same doesn't apply to --raw.

The experimental `nix eval` command already supports a `--raw` flag.
This commit implements the same flag for the stable nix-instantiate command.

Until now instructions and scripts that didn't want to rely on experimental
features had to use workarounds such as:

    nix-instantiate --eval <something> | tr -d \"

(which also undesirably also removes double quotation marks within the string), or

    nix-instantiate --eval <something> | jq -j

(which undesirably depends on another package).

Co-authored-by: Silvan Mosberger <[email protected]>
@not-my-profile
Copy link
Contributor Author

(fixed YAML syntax error in release note frontmatter)

@roberth
Copy link
Member

roberth commented Dec 31, 2024

I think the CI workflow is still awaiting approval.

Didn't have the button for it until I switched back out of the new commit status view beta! (" ✨ Try the new merge experience")

mergify bot added a commit that referenced this pull request Dec 31, 2024
@mergify mergify bot merged commit 18f0770 into NixOS:master Dec 31, 2024
13 checks passed
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-2-26-released/59211/1

@not-my-profile not-my-profile deleted the nix-instantiate-raw branch May 4, 2025 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants