Jump to content

Cheatsheet: Difference between revisions

No edit summary
 
Line 93: Line 93:
=== Explore a NixOS configuration in the REPL ===
=== Explore a NixOS configuration in the REPL ===
If you want to see what ''value'' a NixOS option takes without building, as opposed to merely checking that all options work, you can run:
If you want to see what ''value'' a NixOS option takes without building, as opposed to merely checking that all options work, you can run:
<syntaxHighlight lang="console">
<syntaxhighlight lang="console">
$ nix repl
$ nix repl --file '<nixpkgs/nixos>'
nix-repl> :a import <nixpkgs/nixos> { }
Welcome to Nix 2.18.2. Type :? for help.
 
Loading installable ''...
Added 6 variables.
Added 6 variables.
nix-repl> config.environment.shells  # for example
[ "/run/current-system/sw/bin/zsh" ... ]


nix-repl> config.environment.shells # for example
# Equivalently, if starting from an existing REPL:
</syntaxHighlight>
nix-repl> :l <nixpkgs/nixos>
Added 6 variables.
 
nix-repl> config.environment.shells
</syntaxhighlight>


This can be helpful if your configuration is spread across multiple modules, or if you import modules from external sources, or if NixOS has defaults and you want to know whether a default is being used or extended in your configuration, or a variety of other cases in which you might want the computer to tell you what the end result of all your Nixing is going to be before you switch to it.
This can be helpful if your configuration is spread across multiple modules, or if you import modules from external sources, or if NixOS has defaults and you want to know whether a default is being used or extended in your configuration, or a variety of other cases in which you might want the computer to tell you what the end result of all your Nixing is going to be before you switch to it.
6

edits