How to query the nixos configuration?

I have a configuration.nix file, and I can do nixos-rebuild on it, and can use it with deploy-rs or nixops… But the one thing I cannot figure out how to do properly is to simply query or display some of the options.

For example I want to find out the contents of the list: config.services.xserver.displayManager.session. How can I display that?

And is there something like a cheat-sheat for nix and nixos where something as basic as this is listed?

I think you’re looking for nixos-option: NixOS 23.05 manual | Nix & NixOS (scroll down or ctrl-f “nixos-option”).

Flakes users can use nix repl, :lf and then inspect the nixosConfigurations.

1 Like

For /etc/nixos/configuration.nix there is the nixos-option command in an identically named package:

nix-shell -p nixos-option
nixos-option services.xserver.displayManager.session

For flakes, you can evaluate the option directly:

nix eval .#nixosConfigurations.foo.config.services.xserver.displayManager.session

Or explore interactively in the REPL:

nix repl
:lf .     # or path to your flake
nixosConfigurations.foo.config.services.xserver.displayManager.session
1 Like