Referencing files relative to the root flake.nix

I see 2 options (maybe there are other alternatives):

  • Use a let binding in your home.nix:
{ config, pkgs, ... }:
let rootPath = ../.; in 
{
home.file.".vimrc".source = rootPath + /dotfiles/vim/.vimrc;
}
  • Use the extraSpecialArgs to pass the rootPath:

In flake.nix:

home-manager.nixosModules.home-manager
        {
          home-manager = {
             extraSpecialArgs = {rootPath = ./.;};
          };

And in home.nix:

{ config, pkgs, rootPath, ... }:
...