How to manage dotfiles with home-manager?

I already have a setup with home-manager. The thing I want to know is if there is an easy way rather than doing home-manager switch every time I do a change.

For example, I have my nvim config in ~/dotfiles/config/nvim and my home-manager/home.nix has this setup:

home.file = {
  ".config/nvim" = {
    source = ../config/nvim;
    recursive = true;
  };
}

This is not only for nvim, but for other configs like wezterm, a terminal that reloads the config on save.

Is there a way I could do that with home-manager? Is very tedious to change something and the need of creating a new generation just to see the new change.

Thank you!

2 Likes
home.file = {
  ".config/nvim" = {
    source = config.lib.file.mkOutOfStoreSymlink ../config/nvim;
  };
}

btw if you are using flakes you need to use abslute path as string like:

home.file = {
  ".config/nvim" = {
    source = config.lib.file.mkOutOfStoreSymlink "/home/algus/dotfiles/config/nvim"
  };

if you pass a path instead of string on flakes like in:

home.file = {
  ".config/nvim" = {
    source = config.lib.file.mkOutOfStoreSymlink ../config/nvim;
  };
}

it will copy your config to store before creating a symlink and you will need to home-manager switch --flake everytime (note: --impure might bypass copying i didint tried tough)

note: you can use functions to abstract some of abslute paths

1 Like

Amazing. Thanks for the help :smiley:
This makes it a lot easier for these kind of configurations

1 Like

This is one of the more helpful threads I found by searching for this issue, so I wanted to add something that might be useful. I’m very new to all this, so I’m sorry if it’s obvious!

if you are using flakes you need to use abslute path as string

According to this comment, you can re-use home-manager’s config variable instead of hardcoding the home path. In other words, use ${config.home.homeDirectory} instead of /home/user. Since home-manager requires that be set anyway, and these symlinks are probably going to be created inside the home directory, it seems like a clear way around the “must use absolute paths” issue, as well, without needing other functions.

1 Like