I’m trying to access a (non-flake) private repo I own on github. I have setup github to accept access with ssh-key, and I’ve given github my user’s ssh public key, stored in /home/<username>/.ssh/
The issue is that when I rebuild my system, I do so with sudo nixos-rebuild switch --flake .
, which means that this process is run as root, and root does not look for ssh keys in /home/<username>/.ssh/
hence it doesn’t find an ssh key to access the github repo, and fails.
I have tested this behaviour, and when using
fetchGit {
url="git@github.com:username/secret-repo-name.git";
rev = "[the correct rev number]";
}
in my configuration, the command sudo nixos-rebuild switch --flake .
fails with the following error:
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Additionally, I’ve tried to run
nix eval --expr 'fetchGit { url="git@github.com:username/secret-repo-name.git"; rev = "[again rev number]"; }'
and this command succedes, while running this command with sudo
fails with the same error as above. Because of this I am confident that there must be some issue with using the correct ssh key.
How do other people access private repos?? I’ve seen plenty of references where they just use a variation of this (another way is to use it as a flake input with flake = false
, but it gives the same error), and I haven’t found anywhere anything documenting this issue.
Do other people not have this issue? How do you manage your ssh keys and what public key have you given to github? Should I not be running nixos-rebuild switch
with sudo?
Thanks in advance for any help