It’s all about Path types and String interpolation
This error IMO is not useful. I had to search a little bit more than I wanted to understand what’s going on.
My initial code
The initial code that throws the error does not represent absolute path:
1let
2 pathToFile = "./../vimfiles";
3in
4{
5 vimrcConfig.customRC = (builtins.readFile "${pathToFile}/vimrc.vim")
6}
Solution
Path type have rules, they must contain at least one /, and it is checked before string interpolation.
The way to solve this is to leave literal ./ at the beginning of the Path declaration, when the string interpolation is executed and replace pathToFile with the value defined in the let block, and now the rule that requires the Path type is fulfilled.
1let
2 pathToFile = "../vimfiles";
3in
4{
5 vimrcConfig.customRC = (builtins.readFile ./${pathToFile}/vimrc.vim)
6}
You can find more information in NixOS documentation