iA Blog

How to Reuse Dotfiles config in NixOS

27 Nov 2023 | nixos, nix, dotfiles, vim, lazygit, tutorial

NixOS is great and I’ve migrated most of my linux boxes to NixOS. Nix allows you to configure application-specific settings, removing the need to host a separate doftfiles repository. However, there are still machines like my MacBooks that I prefer to run whatever OS that it came with, and ideally I would like them to share the same dotfiles among them. Instead of configuring each application via nix, I choose to symlink the configs via home-manager:

{ config, ... }: {
  # take lazygit for example
  home.packages = [ pkgs.lazygit ];
  xdg.configFile.lazygit.source = config.lib.file.mkOutOfStoreSymlink "/path/to/dotfiles/dir/lazygit";
}

This will create a symlink from /path/to/dotfiles/dir/lazygit to ~/.config/lazygit.

For dotfiles that are placed outside of ~/.config, the following config will work instead:

{ config, ... }: {
  # take vim for example
  home.packages = [ pkgs.vim ];
  home.file.".vimrc".source = config.lib.file.mkOutOfStoreSymlink "/path/to/dotfiles/dir/vim/.vimrc";
}

This will create a symlink from path/to/dotfiles/dir/vim/.vimrc to ~/.vimrc.


Adwin Ying's avatar
Adwin Ying

Self-taught full-stack web dev based in Tokyo. Occasionally wrecks servers through  self-hosting  and  homelab-ing.

← Back to all posts