:code.priv_dir at compile time and releases

Be really careful about compiling the result of :code.priv_dir or hardcoding the path. I’ve been burned by it before when building on a separate host as the target. I can’t remember the exact issue but it boiled down to it compiling a path on the build machine that didn’t exist on the target machine. Sorry I can’t remember the exact details as it was over a year ago.

You can also use closures as config values.

config, :my_app, metadata_file: fn -> "#{:code.priv_dir(:my_app)}/my_file" end

Application.get_env(:my_app, :metadata_file).()

It’s not always ideal, but it works. I’ve never done it with :code.priv_dir myself, though, so not sure about that one. I’m not sure about using :code in a running system in general, though.

2 Likes