Home-manager and git repo ownership

Complete newb here…

The examples I’m finding advocate git for version control of /etc/nixos, along with home profile configuration using home-manager, with the associated configs living in something like /etc/nixos/home-manager/home.nix.

So having run nixos-rebuild switch as root, to update my home profile I should then switch to my user before running home-manager switch --flake .#mike@hostname, however with the directory under version control, and obviously owned by root, this yields the error:

       … while fetching the input 'git+file:///etc/nixos'

       error: opening Git repository '"/etc/nixos"': repository path '/etc/nixos/' is not owned by current user

The error can be suppressed by running mv .git .gitbak before switching, but I feel I must be missing something.

So, how should I be switching home-manager profiles under version control owned by root? I understand the default config location is ~/.config/home-manager, but I want to keep this all under /etc/nixos, which is what all the examples I see are doing…

You can move the contents of /etc/nixos to a directory in your home directory (remember to chown it!) and run home-manager switch --flake .#mike@hostname from there, you would also need to pass --flake . to nixos-rebuild switch.

1 Like

The issue is that git enforces this.

From Git - git-config Documentation

Git will refuse to even parse a Git config of a repository owned by someone else

So this can also be worked around with the owner of the repository adding to their gitconfig


	directory = /etc/nixos