Write files in nix repl

I’m working my way through the “Nix Pills”; right now I’m on “Functions and Imports”. How do I create a file in repl so it can be imported?

How and why do you want to create a file ? There’s an option to import a file, but i don’t really see why you would create a file instead of writing one without nix repl and then importing it from within the repl.

sometimes its useful for debugging…

nix-repl> example = pkgs.writeText "example.json" (builtins.toJSON (default-toml // this-toml))

nix-repl> :b example
[1 built]

this derivation produced the following outputs:
  out -> /nix/store/avqqvccbv6jbf9yzwlfz9xy7p82qyjzb-example.json