Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding build time ERB/erubis dependency? #51

Open
ersinakinci opened this issue Nov 23, 2019 · 3 comments
Open

Adding build time ERB/erubis dependency? #51

ersinakinci opened this issue Nov 23, 2019 · 3 comments

Comments

@ersinakinci
Copy link

Would folks be open to adding ERB/erubis as a dependency to this project to customize config files during the provisioning step?

Use case

I'm adding support for the parallels-iso builder, which entails setting the hardware.parallels.enable = true option in NixOS to enable Parallels guest OS support. However, I'm currently stuck because this line in parallels-guest.nix conflicts with this line in configuration.nix, resulting in the following error when running packer build:

    parallels-iso: building the configuration in /mnt/etc/nixos/configuration.nix...
==> parallels-iso: error: The option `services.timesyncd.enable' has conflicting definitions, in `/mnt/etc/nixos/hardware-builder.nix' and `/mnt/etc/nixos/configuration.nix' and `/nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/virtualisation/parallels-guest.nix'.
==> parallels-iso: (use '--show-trace' to show detailed location information)
==> parallels-iso: Unregistering virtual machine...
==> parallels-iso: Deleting output directory...
Build 'parallels-iso' errored: Script exited with non-zero exit status: 1.Allowed exit codes are: [0]

In my opinion, the proper way to deal with this is to generate configuration.nix from a template during the provisioning step before it's downloaded by install.sh. In this case, we would stick a conditional that would either emit or omit services.timesyncd.enable = false; from configuration.nix depending on which builder is being used.

I think that using ERB makes sense since Packer and Vagrant use Ruby and erubis is already a Packer dependency.

@PierreR
Copy link
Collaborator

PierreR commented Nov 23, 2019

Do we really need templating ?
We can either move the line services.timesyncd.enable in each builder with the appropriate flag (easy) or use a boolean condition based on the value of config.virtualisation.vmware.guest.enable and cie. I don't really see why the second option would be better than the first in this case.

@ersinakinci
Copy link
Author

I hadn't thought of the option of moving services.timesyncd.enable to the builders, that makes sense. Although now that I think about it, I feel that getting rid of all the builders and replacing them with a templated configuration.nix would be a cleaner approach. If we move services.timesyncd.enable, we'll end up duplicating it across several builders, plus it will decrease visibility by burying it in expressions that are meant to set up virtualization-specific configuration.

Templating is also more scalable for future changes, allowing for more complex logic as we add support for more VM's. And as I mentioned, erubis is already a Vagrant dependency, so it's not like we'll be asking most people to download something new.

I personally wouldn't want to introduce runtime checks in configuration.nix for enabling services depending on whether certain virtualization options have been enabled. That feels brittle.

@PierreR
Copy link
Collaborator

PierreR commented Nov 23, 2019

Fair enough.
As an extra note, there had been some chat about replacing packer with nixops here:
#38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants