I am trying to programmatically extract one of the generated files from a NixOS install. Basically on my NixOS system I run sudo nixos-rebuild switch and as part of the build it writes to /nix/store/<hash>-package/file. I want to output just the contents of that file.
Given that nix is "just" a configuration language and store manager, I believe there should be some way to evaluate /etc/nixos/configuration.nix (and any files imported from it) and do something with the resulting expression to extract the generated file.
I currently can instantiate a new NixOS VM, copy the files in /etc/nixos/ and run sudo nixos-rebuild switch then pull /nix/store/*-package/file from the virtual drive and delete the VM. There has to be a better way?
How can I evaluate /etc/nixos/configuration.nix and dump the contents of one of its generated files even without being on NixOS or loading the configuration?
To clarify, I want to extract a generated file's content from a set of nixos configuration files without loading them as my active nixos configuration.
cat /nix/store/<hash>-package/file... the question is then why don't you just do that?