Is there a way to see the actual computed / generated "output" system configuration built and activated on NixOS?

Viewed 519

So on NixOS we can edit the file /etc/nixos/configuration.nix to specify our "input" system configuration. However, when we run nixos-rebuild switch to build and activate our "input" configuration, then strictly speaking, the actual configuration activated will not exactly be what we had in our "input", but an "output" configuration based on that "input".

Specifically, certain miscellaneous configuration parameters can cause the NixOS logic to insert configuration for additional services not strictly specified in the "input" configuration. Like for example, this here https://github.com/NixOS/nixpkgs/blob/724ed08df02546fea2ab38613d615dd47461528c/nixos/modules/services/web-apps/wordpress.nix#L279 is some NixOS logic that inserts configuration for the MySQL / MariaDB service into the final "output" system configuration, but not because MySQL service was requested in the "input" configuration directly, but because WordPress configuration was specified, and the MySQL service is being activated automatically to facilitate the running of the WordPress instance.

My question is, does anybody know what would be the command or procedure to see this "final" generated "output" configuration that would be the actual configuration built, activated, and running by the system after nixos-rebuild switch?

This would be useful for troubleshooting to be able to assess everything that is running and the actual configuration that it is running with.

1 Answers

The final configuration you mention is the config variable that modules get to use. Its value doesn't consist of purely data, so you can't just serialize it. Some options are function-typed. Not all of it is relevant to your configuration either, because all modules are always loaded into this variable. Even if their main enable option still has the false value, it's still there.

So for troubleshooting, your best option is nix repl:

$ nix repl '<nixpkgs/nixos>'

Loading '<nixpkgs/nixos>'...
Added 6 variables.

nix-repl> config.services.mysql.[press TAB key]
config.services.mysql.bind              config.services.mysql.extraOptions      config.services.mysql.port
config.services.mysql.configFile        config.services.mysql.group             config.services.mysql.replication
config.services.mysql.dataDir           config.services.mysql.initialDatabases  config.services.mysql.rootPassword
config.services.mysql.enable            config.services.mysql.initialScript     config.services.mysql.settings
config.services.mysql.ensureDatabases   config.services.mysql.package           config.services.mysql.user
config.services.mysql.ensureUsers       config.services.mysql.pidDir
nix-repl> config.services.mysql.ensureDatabases
[ ]

nix-repl>

So I don't have any mysql dbs on my laptop.

If you're using flakes, these values are available in the nixosConfigurations.<hostname> attribute.

A flake can be also be loaded in the repl. As of writing it's not quite ideal yet, but this issue will describe the best method to do so.

With Hercules CI Effects, deployments that use the module system generally provide a .prebuilt.config attribute for the same purpose. Here's one for runNixOS.

Related