Search code examples
nix

How to see the tree structure of a remote flake repository


Usually to see the tree structure of a nix variable, I do the following line in the nix interpreter (nix repl)

a={b={c=1;};}
builtins.toJSON a

"{"b":{"c":1}}"

But I have a problem if a comes from a remote project

  a= import (fetchGit { url = "https://github.com/informalsystems/cosmos.nix"; } )
  builtins.toJSON a

error: opening file '/nix/store/ad5kdvzjqy2m4h1alm6amx7mgyzm8463-source/default.nix': No such file or directory

Why does nix try to read something on my computer and how to get rid of this problem.

I've tried another solution:

nix-instantiate --eval --expr 'import (fetchGit { url = "https://github.com/informalsystems/cosmos.nix"; } )'

error: opening file '/nix/store/ad5kdvzjqy2m4h1alm6amx7mgyzm8463-source/default.nix': No such file or directory

but to no avail

update

david grayson gives the answer to the main problem. i.e How to import the github repository. but the builtins.toJSON is not adapted

Whis this code, you can see (without surprised) that the output is a lambda

nix repl

let repo = fetchGit { url = "https://github.com/informalsystems/cosmos.nix"; }; in with repo; let cosmos = import "${repo}/flake.nix";in cosmos.outputs

bash

 nix-instantiate --eval --expr 'let repo = fetchGit { url = "https://github.com/informalsystems/cosmos.nix"; }; in with repo; let cosmos = import "${repo}/flake.nix";in cosmos.outputs'

Solution

  • That's just the way import works: it imports a Nix expression from a file on your computer. When you specify a folder name instead of a filename, it tries to open default.nix in that folder. The project you linked to lacks a default.nix file. You can append a filename like this to tell Nix what file to import:

    a = fetchGit { url = "https://github.com/informalsystems/cosmos.nix"; };
    builtins.toJSON (import "${a}/flake.nix")