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

JSON convert in modules error #1004

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

JSON convert in modules error #1004

wants to merge 2 commits into from

Conversation

jd1t25
Copy link
Contributor

@jd1t25 jd1t25 commented Jun 19, 2024

Hi again,
while continuing following and learning , under Section modules

when you run script "./eval.bash" it shows

{ pkgs ? import <nixpkgs> { } }:
  ^
 error: cannot convert a function to JSON

can we convert function to json in nix? ( did i miss something )
so i just declared pkgs inside "let .... in" block

let
  pkgs = import <nixpkgs> {};
....
in

after executing it shows

while evaluating attribute 'name'
error: cannot convert a function application to JSON

after reading wiki , i followed with --strict

nix-shell -p jq --run "nix-instantiate --eval --json --strict | jq"

now it does show the expected output.

{
  "name": "Boaty McBoatface"
}

Please check on your end , i did double check about the error and also there might be better solution than this

Copy link
Member

@djacu djacu left a comment

Choose a reason for hiding this comment

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

@proofconstruction @fricklerhandwerk Other than my nit I think this is good. I can't think of another way to make the default.nix file work without using --apply and that adds a lot of complexity to the shell script.

source/tutorials/module-system/a-basic-module/default.nix Outdated Show resolved Hide resolved
Co-authored-by: Dan Baker <[email protected]>
@fricklerhandwerk
Copy link
Collaborator

Oh damn, nix-instantiate doesn't do autocall like nix-build and nix-shell.

@fricklerhandwerk
Copy link
Collaborator

This sucks. But we don't have to change the default argument, because that's still useful if you end up building derivations. Just the command line invocation becomes cumbersome and introduces redundancy:

nix-shell -p jq --run "nix-instantiate --eval --json --strict --arg pkgs 'import <nixpkgs> {}' | jq"

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

3 participants