andrewchambers / terraform-provider-nix

terraform provider that manages nix builds and nixos machines.
https://acha.ninja
MIT License
117 stars 5 forks source link

nix_nixos should support config expressions as well as files #10

Closed ocharles closed 5 years ago

ocharles commented 5 years ago

I'm currently using local_file, but it'd really be easier if I could just give nix_nixos a configuration.nix expression:

resource "nix_nixos" "foo" {
  configuration = <<EOT
  { .. }
  EOT
}
andrewchambers commented 5 years ago

Should be pretty easy to support.

andrewchambers commented 5 years ago

I wonder if having only expressions would be better. If you need a file you can always do an expression as "import ./file.nix". I will have a think about it.

andrewchambers commented 5 years ago

It might be slightly trickier than I thought, nixos-rebuild doesn't seem to take expressions for config - so we could send them a patch, and maybe work around by writing a temporary file for each config expression. The main problem is the temporary files can't be in /tmp/ as they need to be in the working dir for relative paths to work properly.

ocharles commented 5 years ago

Ahh, that's a good point. So maybe local_file is the way to go...

ocharles commented 5 years ago

OTOH, we could imagine

resource "nix_nixos" "foo" {
  configuration = <<EOT
  EOT
  working_dir = "/any/path/here";
}

configuration would then create a file in the given working_dir for use with nixos-rebuild.

andrewchambers commented 5 years ago

relative to the current terraform file would be okay, not too sure how to ensure that though.

andrewchambers commented 5 years ago

@ocharles ok, new idea... if configuration_path AND configuration are both set, it means to write the config/build expression to disk at that location, otherwise just read it. I think that resolves the problem.

I think I will prototype it tomorrow.

andrewchambers commented 5 years ago

Ok, this is implemented, you will need to update your config to try it, but the change is quite simple.

You need to change nixos_config to nixos_config_path. Now nixos_config can be used for inline configuration, and the generated config will be written to nixos_config_path.

If you don't need inline config, you just don't specify it and the behavior is the same as before.

ocharles commented 5 years ago

That sounds good to me! Thanks for your work on this, Terraform is starting to look very viable!

On Fri, 19 Apr 2019, 2:43 pm andrewchambers, notifications@github.com wrote:

Closed #10 https://github.com/andrewchambers/terraform-provider-nix/issues/10.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/andrewchambers/terraform-provider-nix/issues/10#event-2288235800, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAFDDT56HQO3KWIXAQFAALPRHEALANCNFSM4HG362QQ .