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

Conditional include based on OS #171

Closed
Firehawke opened this issue May 14, 2024 · 4 comments
Closed

Conditional include based on OS #171

Firehawke opened this issue May 14, 2024 · 4 comments
Labels

Comments

@Firehawke
Copy link

Environment

If applicable, provide the following details:

  • OS: Windows 11 with Ubuntu and NixOS on WSL2
  • Dotter version: 0.13.0

The question

Since I have the same hostname on Windows and WSL, I'm trying to work out how to conditionally include the windows.toml only when running in Windows. This would be the first step in having it only install the Windows Terminal configuration files when run from Windows and ignore it when from any WSL2 distro.

I've tried using the following in the hostname toml file, and it didn't work, as it doesn't seem to like templating at that level. Any suggestions?

{{#if (eq dotter.os windows)}}includes = [".dotter/windows.toml"]{{/if}}
packages = ["windowsterminalpreview"]
@Cornelius-Figgle
Copy link

can you not change the WSL hostname?

@Firehawke
Copy link
Author

Only if I'm willing to sacrifice automatic /etc/hosts generation, which is not a particularly good idea.

@Cornelius-Figgle
Copy link

ah I see. I agree that it would be good if handlebars could be used everywhere.

@SuperCuber
Copy link
Owner

SuperCuber commented Jun 2, 2024

This is not very possible to do, at least not with the way things are implemented right now, since the Handlebars engine is only created once we have gathered and mostly finalized all the configuration (exception made for the if field on files)

The workaround I can think of right now is:

  1. Move most of your configuration out of local.toml and into a shared windows-machine.toml
  2. Define an alias or manually use the -l / --local-config option to select a separate local.toml for each platform.
  3. In each of them, import the windows-machine.toml as well as windows.toml or wsl.toml respectively

I could see it being a feature to have

includes = [{file = ".dotter/windows.toml, if = "(eq dotter.os windows)"}]

But that's very incompatible with how configuration is loaded currently (included files are imported and merged into one big context before Handlebars is initialized)

Feel free to reopen if you have further question :)

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

No branches or pull requests

3 participants