Hey,
I am using NixOS with flakes tracking the unstable branch and I am using doas
with disabled sudo
(becomes important in the end!). Starting about two or three days ago, nixos-rebuild switch
is broken for me. I usually run doas nixos-rebuild switch --flake /path/to/flake#default
and it had always been working perfectly previously. Now I receive the following warnings and errors:
fatal: detected dubious ownership in repository at '/home/username/git/flake/.git'
To add an exception for this directory, call:
git config --global --add safe.directory /home/username/git/flake/.git
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
warning: could not read HEAD ref from repo at '/home/username/git/flake', using 'master'
evaluating derivation 'git+file:///home/username/git/flake#nixosConfigurations."default".config.system.build.nixos-rebuild'fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
error:
⌠while fetching the input 'git+file:///home/username/git/flake'
error: program 'git' failed with exit code 128
Following this error message, I tried the following:
- change the permissions of the git directory (
doas chown -R username:username /path/to/flake
); no change. I even cloned the git repo again, just to make sure - delete
.git
directory; works again like before, but this is hardly an acceptable solution - having a
dirty
git worktree; works, but again not really an acceptable solution - rename
main
branch tomaster
. This fixes the error, but the warnings remain (and now they appear twice):
fatal: detected dubious ownership in repository at '/home/username/git/flake/.git'
To add an exception for this directory, call:
git config --global --add safe.directory /home/username/git/flake/.git
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
warning: could not read HEAD ref from repo at '/home/username/git/flake', using 'master'
building the system configuration...
fatal: detected dubious ownership in repository at '/home/username/git/flake/.git'
To add an exception for this directory, call:
git config --global --add safe.directory /home/username/git/flake/.git
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
warning: could not read HEAD ref from repo at '/home/username/git/flake', using 'master'
Note that all other git
actions (like git add
, git commit
) work without any warnings.
Out of curiosity, I tried enabling sudo
and ran sudo nixos-rebuild switch --flake /path/to/flake#default
and suddenly it worked normally.
I checked if anyone else had the same problem and came across this post. However, the solution is not applicable since I already have
security.doas.extraRules = [{
users = [ "wheel" ];
keepEnv = true;
}];
in my configuration and my current user is part of the wheel
group.
My question now is, if this is a bug or just a configuration problem (i.e. expected behaviour)? If it is a bug, is the nixpkgs
Github the correct place to write a bug report; is this an issue with nix
, git
or some library nixos-rebuild
uses internally? I would appreciate your help