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

Add --argjson similiar to --argstr to allow passing JSON into nix from the command-line. #6059

Open
tomprince opened this issue Feb 7, 2022 · 0 comments

Comments

@tomprince
Copy link

Is your feature request related to a problem? Please describe.
When using nix programatically, it is useful to pass in structured data to a nix expression.

Describe the solution you'd like
I'd like to be able to pass --argjson args '{"some": "args"}' and have the nix expression receive the nix value {some = "args";}, rather than needing to use --argstr and then builtins.fromJSON on the result. The would mean the expression being called doesn't need to make allowances for being called from outside nix, and can just take a structured value.

Describe alternatives you've considered
It is currently possible to do this via something like

# example.nix
{ argsJSON ? null, args ? builtins.fromJSON argsJSON }: /* stuff using args */

and running it with nix build -f example.nix --argstr '{"some": "args"}.

Additional context

For example, in https://github.com/DBCDK/morph/pull/186/files#diff-cf26037a329af2f212a4b7c055c4466aaa4d04fae33fc0a711a6353291025e57R111 I need some extra logic to deal with potentially being passed a JSON argument. If instead there was --argjson, I could just pass --argjson names '["node1", "node2"] and remove the logic in nix around argsJSON. I currently have code like the following

{
  names ? null,
  argsJSON ? null,
}:
  assert argsJSON != null -> names == null;
  let
    names' = if argsFile != null then
        (builtins.fromJSON argsJSON).names
      else
        names;
  in ...

but with this option, I could simply have

{ names }: ...`
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

No branches or pull requests

2 participants