0

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.

3
  • 1
    I don't understand what you're asking. At face value you seem to want to cat /nix/store/<hash>-package/file ... the question is then why don't you just do that? Commented Nov 8 at 22:56
  • I want to get the same effect without loading the config. As an example, lets say my friend hands me his nixos configuration directory and I want to copy his nginx configuration, but don't want to load his whole system. He might have many packages that interact with nginx to make arbitrarily complicated nginx config files. I just want that config. Commented Nov 8 at 23:02
  • How about you edit your question to that effect ... may help others understanding it, too, without having to read through the comment section. Commented Nov 9 at 3:44

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.