How is environment variable substitution done in a home manager imported module?

OS: macOS, 13.2.1 (Ventura)
Nix: 2.12.0
Home-Manager: 22.11

(If I’ve poorly titled the question, please say, and I’ll edit it.)

I’ve installed asdf-vm via git because it’s not available for x86_64-darwin, and having zsh installed via home-manager, I want to do the following as per the installation instructions at Install asdf > ZSH & Git:

Add the following to ~/.zshrc :
. “$HOME/.asdf/”

I’ve changed this to

. "${ASDF_DIR}/"

based on my env variables in my /etc/zshenv (with the goal of moving my dotfiles into ~/.config eg ~/.config/asdf).

My dir/file setup is:

/etc/zshenv <-- export ASDF_DIR="${XDG_CONFIG_HOME}/asdf
~/.config/nixpkgs/flake.nix <-- home manager
~/.config/nixpkgs/home_manager/modules/shell/zsh.nix <-- initExtra

To do the above, I’m attempting the following in my home_manager/modules/shell/zsh.nix:

initExtra = "
  . "${ASDF_DIR}/";

which gives:

error: syntax error, unexpected DOLLAR_CURLY, expecting ';'

Is this because I am not using substituteAll and if so, how do I use it so ${ASDF_DIR} is substituted, and am I putting . "${ASDF_DIR}/" in the right block in my zsh.nix file imported into my home-manager flake?

You need to escape the ${. And you want to use a double-single-quoted-string actually:

initExtra = ''
  . "''${ASDF_DIR}/";
1 Like

Thanks @NobbZ,

(My apologies for the very late reply - big commute etc.)

Do you wear a cape, because you’re a super hero to noobs like me?!?

That worked and I’m back to developing using elixir via asdf… and now nix too!

I wondered if I should just escape the $, but I wasn’t sure how to, and many thanks too for clarifying the double-single-quote thing - was confusing for me (at least) via the docs and github examples. I’m constantly learning from you and this awesome community!