Skip to content

Instantly share code, notes, and snippets.

@crabdancing
Last active November 12, 2024 05:41
Show Gist options
  • Save crabdancing/fd14d7e4fb209e13012d071046fbed37 to your computer and use it in GitHub Desktop.
Save crabdancing/fd14d7e4fb209e13012d071046fbed37 to your computer and use it in GitHub Desktop.
a quick nix repl tutorial

If you want to probe a nix flake and figure out what it exposes, I typically just load it into nix repl and then tab complete around until I find what I'm looking for. E.g.:

$ nix repl
Welcome to Nix 2.18.5. Type :? for help.

nix-repl> :lf github:wez/wezterm/main?dir=nix
Added 12 variables.

nix-repl> outputs.packages.
outputs.packages.aarch64-darwin  outputs.packages.x86_64-darwin
outputs.packages.aarch64-linux   outputs.packages.x86_64-linux
nix-repl> outputs.packages.x86_64-linux.default

lf here stands for load flake. There are also a bunch of other commands in nix repl that are great to learn.

Here, I hit tab on outputs.packages. and it showed me the archs, then I hit tab once I typed the arch and I got default.

Incidentally, if you want to build it right from the repl, after loading the flake, you can do:

nix-repl> :b outputs.packages.x86_64-linux.default

This derivation produced the following outputs:
  out -> /nix/store/fvdqjmr72563rkizmcg1ydbwgdlj92f5-wezterm

You can then just run that wezterm and test it out, if you want!

$ /nix/store/fvdqjmr72563rkizmcg1ydbwgdlj92f5-wezterm/bin/wezterm --version
wezterm 30345b3

Note that you can also point :lf at a flake on disk, too, if you want. E.g., if you are using a system flake:

$ nix repl
:lf /etc/nixos

You can now probe around and see what your system flake exposes! E.g., under outputs.nixosConfigurations.<node> you can inspect the configuration of the machine or manually build any derivations it exposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment