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

Realise a string with context #7654

Open
roberth opened this issue Jan 21, 2023 · 1 comment
Open

Realise a string with context #7654

roberth opened this issue Jan 21, 2023 · 1 comment
Labels
cli The old and/or new command line interface feature Feature request or proposal new-cli Relating to the "nix" command repl The Read Eval Print Loop, "nix repl" command and debugger

Comments

@roberth
Copy link
Member

roberth commented Jan 21, 2023

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Sometimes I just want to paste a string into my shell and run it.

For example

nix-repl> config.system.activationScripts.check-manual-docbook
"if [[ $(cat /nix/store/zvzbmg408jbb7x60kdwndfv68x7mlcnj-options-used-docbook) = 1 ]]; then\n  echo -e \"\\e[31mwarning\\e[0m: This configuration contains option documentation in docbook.\" \\\n          \"Support for docbook is deprecated and will be removed after NixOS 23.05.\" \\\n          \"See nix-store --read-log /nix/store/6vknjm2hbvqpwql7qp1dxhg4hbq5hs26-options.json.drv\"\nfi\n"

nix-repl> :b config.system.activationScripts.check-manual-docbook
error: expression does not evaluate to a derivation, so I can't build it

Describe the solution you'd like

In the repl, when :b evaluates its argument to a string, continue to build the string context. Maybe print the raw string? (ie not in string literal syntax)

In the cli, add a flag to build a string? An nix eval flag? A nix build flag?

e.g.

$ s=$(nix eval --raw --realise nixpkgs#hello.shellHook)
eval "$s"

or perhaps something like

$ s=$(nix build --stdout=string nixpkgs#hello.shellHook)
eval "$s"

or something like --print=raw or --print=json.

Describe alternatives you've considered

a. Keep digging through toplevel instead of building the option I wish to inspect.

b. Write ad hoc script builder in the repl. This is not the same, as the result is a bit harder to read, and the script derivation is slightly cumbersome to write.

Additional context

Priorities

Add 👍 to issues you find important.

@roberth roberth added feature Feature request or proposal cli The old and/or new command line interface labels Jan 21, 2023
@roberth roberth changed the title Build a string with context Realise a string with context Jul 14, 2023
@roberth roberth added repl The Read Eval Print Loop, "nix repl" command and debugger new-cli Relating to the "nix" command labels Jul 14, 2023
@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/lib-getexe-and-lib-getexe-are-not-safe/43529/16

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 feature Feature request or proposal new-cli Relating to the "nix" command repl The Read Eval Print Loop, "nix repl" command and debugger
Projects
None yet
Development

No branches or pull requests

2 participants