Search code examples
gitnixnixos

how put my /etc/nixos/configuration.nix on github


First I show you the same procedure in a normal directly:

git init
git add .
git commit -m "first commit"

In an normal directory (~/testGit for instance), it works without problem.

I want to do the same in the directory /etc/nixos.

First I have to do this:

git config --global --add safe.directory /etc/nixos

otherwise I get this message:

fatal: detected dubious ownership in repository at '/etc/nixos' To add an exception for this directory, call:

   git config --global --add safe.directory /etc/nixos

The 2 first commands work well although I have to use sudo:

sudo git init
sudo git add .

but the third one fails

sudo git commit -m "first commit"

Author identity unknown

*** Please tell me who you are.

Run

git config --global user.email "[email protected]" git config --global user.name "Your Name"

to set your account's default identity. Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'root@nixos.(none)')

Of course I followed the instructions:

git config --global user.email "[email protected]"
git config --global user.name "MY Name"

but it still doesn't work.

In am running nixos on virtualbox. I don't think it is important but at least you know.


Solution

  • git config --global sets stuff globally for the user, i.e., in ~/.gitconfig, not for the whole system, like in /etc/git or such. "Globally" means really "for all git repositories this user accesses from this machine".

    Run the git config commands with sudo to set the root user's git credentials:

    sudo git config --global user.email "[email protected]"
    sudo git config --global user.name "MY Name"
    

    After this, if you use an external service like github and authenticate with ssh, you may also need to copy your ssh key (or better create a new one for root) and add that to root's ~/.ssh settings.

    Because ssh really cares about file ownership and permissions, you may need to sudo chown -R root ~root/.ssh and sudo chmod 600 ~root/.ssh/*