2

I recently started using NixOS version 23.05.885.bb8b5735d6f. I see some (predefined) expressions in the configuration, but I don't know what could be the actual value bound to these.

For instance, I have hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; set in /etc/nixos/hardware-configuration.nix, and I would like to know what would be the actual value of config.hardware.enableRedistributableFirmware — because I'm expecting this to be set to true.

Is there a way to retrieve what config.hardware.enableRedistributableFirmware (or any other) currently evaluates to from the (Bash) console or using another method?

I have some others way to verify this (for this particular case):

[x80486@uplink:~]$ journalctl --dmesg --grep microcode
Jun 26 08:19:28 uplink kernel: microcode: microcode updated early to revision 0xf2, date = 2023-01-12
Jun 26 08:19:28 uplink kernel: SRBDS: Mitigation: Microcode
Jun 26 08:19:28 uplink kernel: microcode: sig=0x906ea, pf=0x2, revision=0xf2
Jun 26 08:19:28 uplink kernel: microcode: Microcode Update Driver: v2.2.

...but again, I would like to be able to figure it out what the final configuration values will be.

2 Answers 2

2

You can check it in the Nix REPL:

$ nix repl --file '<nixpkgs/nixos>'
Welcome to Nix 2.13.3. Type :? for help.

Loading installable ''...
Added 6 variables.
nix-repl> config.hardware.enableRedistributableFirmware
true
4
  • Isn't that the default value from nixpkgs? How can we use the repl to retrieve the final value after also evaluating our nix code? (In some cases it might be easy to grep through my code to find the value I set it to but if the value is defined dynamically in my code I would like to eval it all)
    – Lucas
    Commented Jul 14, 2023 at 10:08
  • This gives me error: unrecognised flag '--file'. If I replace that with nix repl -I '<nixpkgs/nixos>' then it seems config is not defined (do I need to import it?) nix-repl> config.hardware.enableRedistributableFirmware error: undefined variable 'config'. Commented Aug 25, 2023 at 9:41
  • @ChrisStryczynski Sounds like your install is either old or broken. It still works for me with Nix 2.13.5.
    – l0b0
    Commented Aug 25, 2023 at 9:45
  • About a year-ish old yes. Running 22.05, nix version 2.8.1. Commented Aug 25, 2023 at 9:55
1

You can also use nix-instantiate to get value of evaluated config,

nix-instantiate --eval --expr 'with import <nixpkgs> {}; with lib; import <nixpkgs/nixos/lib/eval-config.nix> {
  inherit system; modules = [
    { options.a = lib.mkOption { type = types.int; }; config.a = lib.mkDefault 1; }
    { config.a = 5; }
    ];
}' -I nixpkgs=channel:nixos-23.05 -A config.a

5

More specific example, if you have a configuration.nix, home.nix or something,

nix-instantiate --eval --expr 'import <nixpkgs/nixos/lib/eval-config.nix> { system = builtins.currentSystem; modules = [ ./configuration.nix ]; }' -I nixpkgs=channel:nixos-23.05 -A config.system.build.toplevel.outPath

-A is used to query an attribute after nix expression evaluation.

You must log in to answer this question.