Skip to content

Instantly share code, notes, and snippets.

@axelbdt
Created April 11, 2023 14:10
Show Gist options
  • Save axelbdt/0de9f5f9ba8a2100326b793f7bfb8658 to your computer and use it in GitHub Desktop.
Save axelbdt/0de9f5f9ba8a2100326b793f7bfb8658 to your computer and use it in GitHub Desktop.
How to Install asdf with Nix Home-manager

How to Install asdf with Nix Home-manager

  1. First, add asdf to the Nix configuration with the package named asdf-vm. Add the following line to your configuration.nix file:

    environment.systemPackages = with pkgs; [
      asdf-vm
    ];
  2. Next, add the following lines to your .bashrc file:

    . "$HOME/.nix-profile/share/asdf-vm/asdf.sh"
    . "$HOME/.nix-profile/share/bash-completion/completions/asdf.bash"

    These lines will load asdf into your shell.

  3. Reload your .bashrc or open a new terminal to apply the changes.

  4. Verify that asdf is properly installed by running the following command:

    asdf --version

    This should output the version number of asdf.

That's it! Now you can use asdf with Nix.

@fkrause98
Copy link

Thanks for this, It's really useful.

For anyone that's using fish, do this on step 2:

## Loads asdf definitions
source "$HOME/.nix-profile/share/asdf-vm/asdf.fish"

@felipelalli
Copy link

felipelalli commented Feb 18, 2024

In my case, the installation did not create the paths inside ".nix-profile" like:

.nix-profile/share/asdf-vm/

So I put it in my .bashrc:

. "/run/current-system/sw/share/asdf-vm/asdf.sh"
. "/run/current-system/sw/share/bash-completion/completions/asdf.bash"

@milespossing
Copy link

Using home-manager with bash I used something like this to ensure it always looked in the right place:

programs.bash = {
  enable = true;
  # ... other things here
  initExtra = ''
    . "${pkgs.asdf-vm}/share/asdf-vm/asdf.sh"
    . "${pkgs.asdf-vm}/share/asdf-vm/completions/asdf.bash"
  '';
};

@diegodorado
Copy link

for me, i had to load bashcompinit on zsh to make it work:

  programs.zsh = {
    enable = true;
    initExtra = ''
      . "${pkgs.asdf-vm}/share/asdf-vm/asdf.sh"
      autoload -Uz bashcompinit && bashcompinit
      . "${pkgs.asdf-vm}/share/asdf-vm/completions/asdf.bash"
    '';
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment