Asdf: Common location for default packages for all plugins

Created on 29 Mar 2020  路  6Comments  路  Source: asdf-vm/asdf

Idea

Currently asdf-nodejs, asdf-ruby and asdf-python among other plugins allow for $HOME/.default-<tool>-packages config files. It is clear from the discussions in each plugin that people want to be able to configure the file location.

Proposals

Perhaps asdf core can provide plugins with ASDF_CONFIG dir that is the directory of .asdfrc by default?


This way, users can configure this, and plugin authors can focus on the default packages filename appropriate for their plugin and install those packages instead of also having to support a diverging set of dirs.

Or perhaps this is too much and simply doing:

default_gem_path() {
  local config_path=${ASDF_CONFIG_FILE:-"$HOME/.asdfrc"}
  local config_dir=$(dirname "$config_path") 

in each plugin is enough. (This was proposed in asdf-ruby https://github.com/asdf-vm/asdf-ruby/pull/114/files)

Related

proposal

Most helpful comment

I would advocate for making asdf core XDG complaint. It should be possible to do this in a backwards compatible way like many other tools have done in the past. Currently I do the following:

export ASDF_DATA_DIR="${XDG_DATA_HOME:-~./local/share}/asdf"
export ASDF_CONFIG_FILE="${XDG_CONFIG_HOME:-~./config}/asdf/asdfrc"

Introducing an ASDF_CONFIG_DIR variable would allow for something like this:

export ASDF_CONFIG_DIR="${XDG_CONFIG_HOME}/asdf"
export ASDF_CONFIG_FILE="${ASDF_CONFIG_DIR}/asdfrc"
export ASDF_NODEJS_DEFAULT_PACKAGES="${ASDF_CONFIG_DIR}/nodejs_default_packages"

The ASDF_CONFIG_FILE variable would then default to using the ASDF_CONFIG_DIR as the base directory (defaulted to $HOME/.config/asdf) unless overridden. Any plugins can then start using the ASDF_CONFIG_DIR as the base config directory and/or provide a custom environment override as needed.

All 6 comments

The main reason I would want to see this is to be more XDG compliant. For instance, I currently do the following in order to keep my $HOME directory cleaner.

export ASDF_CONFIG_FILE="${XDG_CONFIG_HOME}/asdf/asdfrc"

Ideally the ${XDG_CONFIG_HOME} would be the default location for all asdf related config files vs $HOME. Currently it's possible to override this for some parts of asdf via environment variable, but not for deafult-* files.

I know some existing version managers (like rbenv for Ruby) currently look for .default-gems in the users home directory. I don't know if rbenv allows the user to customize the location of the file, but I would guess most rbenv users don't, so ideally asdf-ruby would look for .default-gems in the users home directory by default too. I'm open to a new feature that allows users to better organize things with asdf, but I also think we should imitate the behavior of other widely used legacy version managers whenever possible.

To be clear, I brought up XDG as a very valid example of why people may want to override the location of these files. Currently the default-* files are the only standard parts I'm unable to do this with.

In regards to rbenv, the rbenv-default-gems plugin does allow you to override the default directory. I believe it uses $(rbenv root)/default-gems which before I switched to asdf :) could be set with export RBENV_ROOT="${XDG_DATA_HOME}/rbenv" (which would = ~/.local/share/rbenv on most systems).

I agree that we should imitate the behavior of legacy version managers by default. If no ENV variable is set then that should be the default behavior. I do notice that there are a few PR's still open which do adhere to this meanwhile providing an option to override this. This does raise the question: should the core enforce this or leave it up to the plugins to decide on their own? The latter would be more suited.

I would also like to see these changes in the plugin. My reason is that I also follow the principles of XDG and have moved most of my configuration to ~/.config/asdf/ on my macOS system.

For reference and inspiration, here are a few PR's which propose the ability to move default package files to custom locations.

https://github.com/danhper/asdf-python/pull/63 (merged)
https://github.com/asdf-vm/asdf-nodejs/pull/170 (merged)
https://github.com/asdf-vm/asdf-ruby/pull/114

Sounds like we're all on the same page; support existing ecosystem defaults with a config var for custom location. Should this be part of the asdf core though?

I would advocate for making asdf core XDG complaint. It should be possible to do this in a backwards compatible way like many other tools have done in the past. Currently I do the following:

export ASDF_DATA_DIR="${XDG_DATA_HOME:-~./local/share}/asdf"
export ASDF_CONFIG_FILE="${XDG_CONFIG_HOME:-~./config}/asdf/asdfrc"

Introducing an ASDF_CONFIG_DIR variable would allow for something like this:

export ASDF_CONFIG_DIR="${XDG_CONFIG_HOME}/asdf"
export ASDF_CONFIG_FILE="${ASDF_CONFIG_DIR}/asdfrc"
export ASDF_NODEJS_DEFAULT_PACKAGES="${ASDF_CONFIG_DIR}/nodejs_default_packages"

The ASDF_CONFIG_FILE variable would then default to using the ASDF_CONFIG_DIR as the base directory (defaulted to $HOME/.config/asdf) unless overridden. Any plugins can then start using the ASDF_CONFIG_DIR as the base config directory and/or provide a custom environment override as needed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

point-source picture point-source  路  4Comments

peleteiro picture peleteiro  路  3Comments

michalmuskala picture michalmuskala  路  5Comments

robsonpeixoto picture robsonpeixoto  路  4Comments

jamesstidard picture jamesstidard  路  4Comments