How to manage my dotfiles

I’ve to admit i always mess up my dotfiles using git, however i think it’s the best way since the only program you need to fetch your config is git, i’m not really interested in gnu stow or other programs, however when it comes to nix i’m a bit confused about how to setup my dotfiles since i have my .config/nixpkgs and some other folders inside .config/ Then it would be reasonable to have a git bare repo but then i’m excluding my /etc/nixos/ folder which contains my whole system config.

I was thinking about using the following structure but it would require to mount the /etc/nixos folder inside my $HOME

├── .config
│   ├── bspwm
│   │   └── bspwmrc
│   ├── fd
│   │   └── ignore
│   ├── nixpkgs
│   │   ├── console.nix
│   │   ├── graphical.nix
│   │   ├── home.nix
│   │   ├── music.nix
│   │   └── text-editor.nix
│   ├── sxhkd
│   │   └── sxhkdrc
│   └── tint2
│       ├── tint2rc
├── etc
│   └── nixos
│       ├── configuration.nix
│       └── hardware-configuration.nix
  1. What do you think about this setup? any suggestion?

  2. How can i declare inside my configuration.nix that /etc/nixos/ should be mounted inside my home by default?

  3. How do YOU manage your system dotfiles alongside with your $HOME folder and your home-manager config.

1 Like

There are so many options for this, and I don’t know which you’ll prefer but, personally, I don’t keep my nixos config files in /etc, so they don’t raise any special problem.

I’ve since switched to flake-based solution, which, though rather a chore to setup, is to my mind much cleaner. However, when I was using just home-manager I had a subdirectory in my dotfile repo, ~/dot/system/, in which I put configuration.nix and hardware-configuration.nix and which I linked to /etc/nixos. Then all I needed to do on installation (for the system config) was link the directory and run nixos-install. As for home-manager, I linked the entire dotfile repo to ~/.config/nixpkgs and it happily ignored my system config. I mention this as more a cautionary tale than a recommendation.

That said, I suggest at some point checking out nix flakes as you can specify your entire config (both system and user) from one flake.nix in your dotfiles. Since the flake used to (re)build the system can be specified by an arbitrary path upon rebuild (with something like sudo nixos-rebuild switch --flakes "/path/to/flake#hostToRebuild), you can simply clone your dotfiles and that’s that–no fiddly linking! I found hlissner’s dotfiles, among others, extremely helpful in migrating my configuration to flakes.

This has nothing to do with flakes.

You can put the system configuration in any file and just point nixos-rebuild to it with the -I flag:

nixos-rebuild switch -I nixos-config=<path to file>

So in any case it doesn’t matter where you put your configuration files or how you structure them. Just specify the entry point somehow.


Ah. You’re quite right. Most of the configs I’ve looked at that use home-manager as a NixOS module also use flakes and I misattributed the convenience of a single entry point to flakes rather than the home-manager as a module.

I have my dot files in the same repo as the Nix config and symlink some configs to ~/.config/ with home-manager similar to what I’ve been doing with stow before.
The great thing about this is that I can still use my previous configs and step by step integrate it more into Nix native configs.
You can even link whole folders like with the highlighted MPV example.
Be aware that I’m quite new at this as well.


I just found out that if you symlink the flake.nix file to /etc/nixos/flake.nix like with the configuration.nix and then you can just run sudo nixos-rebuild switch like before.

1 Like
  1. seems ok, although I think symlinking /etc/NixOS to something inside .config would be easier than mounting.
  2. not sure about mounting, bit for symlinking I do this once manually. I wish there was a simple declarative way to do that.
  3. I put dot files in ~/config, and have a script doing symlinking. On balance, I like linking more than a bare repo, as everything I version is in a single dir.

home-manager tires to solve dot files problem, but it doesn’t work for me. It is oriented around a multi-user system, where programs are installed in the user’s profile. I run a single user system, where I just installed all stuff globally. I wish there were something like home-manager, where I get to declaratively configure things via nix, but which still uses standard NixOS approach with global packages.

1 Like

Nothing prevents you from declaring the packages in the global NixOS config and just using home-manager to symlink the configs.
I have a lot of packages in the global config and only some in home-manager.
I try to split into system an user packages.
So something like htop is a system package for me and VSCode is a user package.

I didn’t know about that feature, thanks