NixOS config error: 'does not represent an absolute path'

Written by Lyoneel on in troubleshooting, NixOS
 1 min

NixOS config error: 'does not represent an absolute path'

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:

let
  pathToFile = "./../vimfiles";
in
{
  vimrcConfig.customRC = (builtins.readFile "${pathToFile}/vimrc.vim")
}

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.

let
  pathToFile = "../vimfiles";
in
{
  vimrcConfig.customRC = (builtins.readFile ./${pathToFile}/vimrc.vim)
}

You can find more information in NixOS documentation