deadc0de6 / dotdrop

Save your dotfiles once, deploy them everywhere
https://dotdrop.readthedocs.io
GNU General Public License v3.0
1.79k stars 105 forks source link

[help] Understanding the docs on variables in config file #347

Closed RayZ0rr closed 2 years ago

RayZ0rr commented 2 years ago

I am reading the variables section of the config file. I don't understand some of the points listed there:

1.

Config files do not have access to variables defined above in the import tree.

What does this mean? Does it refer to variables in import_configs ?

2.

Interpreted variables and variables are templated before interpreted variables are executed.

and

dynvariables take precedence over variables

Aren't these two statements contradictory?

deadc0de6 commented 2 years ago

Yeah I agree it's not totally clear. I'll refactor those parts of the doc. Below you'll find answers to both your questions but if anything is still unclear don't hesitate to let me know.

1.

It means that variables defined in the importing file won't be defined in the imported file (also applying to all import options import_configs, import_variables, import_actions, profile's import and profile's include). I'll update the doc but let me give you an example:

config_top.yaml defines variable topvar and imports the config file config_bottom.yaml. This rule means that inside config_bottom.yaml the variable topvar won't be defined.

2.

They are not contradictory. It is maybe better explained in the CONTRIBUTING doc but let me explain:

Interpreted variables and variables are templated before interpreted variables are executed. should be read dynvariables and variables are templated before dynvariables are executed through the shell. This made me realize that the doc had a outdated example:

config example

dynvariables:
  user: "echo $USER"
  config_file: echo "{{@@ user_config @@}}"
variables:
  user_config: "profile_{{@@ user @@}}_uid.yaml"

with a dotfile containing

{{@@ user @@}}
{{@@ config_file @@}}
{{@@ user_config @@}}

results in (with $USER being someuser)

someuser
profile_echo .yaml
profile_echo $USER_uid.yaml

This shows that variables and dynvariables are first templated and then the dynvariables are executed. I'm gonna fix the example in the doc too, thanks for making me see this.

Then dynvariables take precedence over variables simply means means that if you have some key defined by both a variable and a dynvariable, then the variable one will be ignored.

dynvariables:
  somevar: "echo $USER"
variables:
  somevar: "echo $USER"

The variable somevar will get the value of the environment variable $USER and not echo $USER.

RayZ0rr commented 2 years ago

Thank you very much for the quick and clear response.