Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git 2.35.2 breaks nixos-rebuild with flake repo owned by non-root user #169193

Closed
NickCao opened this issue Apr 18, 2022 · 41 comments · Fixed by ksevelyar/idempotent-desktop#11 · May be fixed by #170501
Closed

git 2.35.2 breaks nixos-rebuild with flake repo owned by non-root user #169193

NickCao opened this issue Apr 18, 2022 · 41 comments · Fixed by ksevelyar/idempotent-desktop#11 · May be fixed by #170501

Comments

@NickCao
Copy link
Member

NickCao commented Apr 18, 2022

Describe the bug

After upgrading to git 2.35.2 (which is the version currently in nixos-unstable-small), running sudo nixos-rebuild switch with a flake repo owned by non-root user would result in a cryptic error message saying

warning: Not a git repository. Use --no-index to compare two paths outside a working tree
usage: git diff --no-index [<options>] <path> <path>
...... (the full git diff help)
error: program 'git' failed with exit code 129
(use '--show-trace' to show detailed location information)

The underlying reason is that due to the fix for CVE-2022-24765, git now effectively treats any directory not owned by the calling user as not a git repo. A temporary workaround would be to add the repo to safe.directory entry of the root user's git config. A possible long term fix is to only use sudo or others means for privilege elevation when absolutely required in nixos-rebuild.

Notify maintainers

@Profpatsch

Metadata

 - system: `"x86_64-linux"`
 - host os: `Linux 5.17.3, NixOS, 22.05 (Quokka), 22.05.20220418.f26866c`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.8.0pre20220411_f7276bc`
 - nixpkgs: `/nix/store/xy6wkddgna3rsmqkb53120x8lpf1pbvr-source`
@andrevmatos
Copy link
Member

andrevmatos commented Apr 18, 2022

This also breaks sudo nixos-container --flake for the same reason

@izik1
Copy link
Contributor

izik1 commented Apr 18, 2022

Note: An extra hacky work around if you can't modify root's gitconfig (say, because you'd need to use this same flake to do so) is to chown the directory to root, do your temp fix, and chown it back 🤣 (I wouldn't recommend doing that unless you have to and know what you're doing)

@hqurve
Copy link
Contributor

hqurve commented Apr 19, 2022

Can we also build the config using unprivileged nixos-rebuild build --flake and then run sudo ./result/bin/switch-to-configuration <action>?

@SuperSandro2000
Copy link
Member

Such a nonsense CVE 🙄 If people can drop malicious files on your filesystem you are already fucked.

@SuperSandro2000
Copy link
Member

Workaround to get your machines updated

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

@NickCao
Copy link
Member Author

NickCao commented Apr 20, 2022

Just found out that nixos-rebuild has a --use-remote-sudo flag, which does exactly my second solution.

@NickCao NickCao closed this as completed Apr 20, 2022
@SuperSandro2000
Copy link
Member

I am questioning myself: Why is this not the default? Sounds like it should be to me.

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/sudo-nixos-rebuild-switch-not-a-git-repository/18763/2

1sixth added a commit to 1sixth/flakes that referenced this issue Apr 23, 2022
mrkkrp added a commit to mrkkrp/nixos-config that referenced this issue Apr 23, 2022
mrkkrp added a commit to mrkkrp/nixos-config that referenced this issue Apr 23, 2022
@Artturin
Copy link
Member

lets keep this open until something is done so this works by default

@Artturin Artturin reopened this Apr 23, 2022
@Artturin Artturin pinned this issue Apr 23, 2022
khrj added a commit to khrj/nixos-config that referenced this issue Apr 24, 2022
Requires `sudo git config --global --add safe.directory /home/khushraj/nixos-config/` see NixOS/nixpkgs#169193
@matklad
Copy link
Member

matklad commented Apr 24, 2022

(not sure if its worth opening an issue about)

For extra dwim, it'd be cool if --use-remote-sudo just worked for those of us who use doas rather than sudo.

@TLATER
Copy link
Contributor

TLATER commented Apr 25, 2022

To spell out @NickCao 's work-around, you can use nixos-rebuild --use-remote-sudo for your local system as well, which is both ingenious and a bit silly (and will from now on be how I invoke nixos-rebuild in general).

@wiltaylor
Copy link
Contributor

@hqurve this seems like the best way to fix this moving forward.

@Sciencentistguy
Copy link
Member

Is there a reason not to make --use-remote-sudo the default behaviour?

@TLATER
Copy link
Contributor

TLATER commented Apr 26, 2022

Is there a reason not to make --use-remote-sudo the default behaviour?

Having the toggle is desirable for systems where you don't have sudo, and want to hand-craft permissions with any of the non-sudo permissions management options instead. But in those cases it's not really harmful and should show a pretty obvious error message. I can't really see a reason not to invert that flag.

@ncfavier
Copy link
Member

We should also probably replace remote-sudo with just sudo given that it applies to local builds.

@dasJ

This comment was marked as resolved.

@dasJ dasJ unpinned this issue May 29, 2022
@dasJ dasJ pinned this issue May 29, 2022
@ocfox
Copy link
Member

ocfox commented Jun 3, 2022

I found that this also works fine nix-shell -p git --run "sudo nixos-rebuild switch".

@kirillrdy
Copy link
Member

with upgrade to nix 2.9.0, this is started happening to me again

@Artturin
Copy link
Member

Artturin commented Jun 6, 2022

with upgrade to nix 2.9.0, this is started happening to me again

The nix bump isn't in any of the channels yet, https://nixpk.gs/pr-tracker.html?pr=175541

@LukaKon
Copy link

LukaKon commented Jun 8, 2022

After upgrade nix to 2.9: warning: Not a git repository. Use --no-index to compare two paths outside a working tree
and same situation in nix-shell :)

@infinisil infinisil unpinned this issue Jun 9, 2022
@infinisil infinisil pinned this issue Jun 9, 2022
@Radvendii
Copy link
Contributor

This also affects url = "path:/foo/bar" type flake inputs when they're git repos.

@Artturin
Copy link
Member

Artturin commented Jun 9, 2022

NixOS/nix#6636

@Artturin
Copy link
Member

Artturin commented Jun 12, 2022

stable: #177353
unstable: #177184

leotaku added a commit to leotaku/nixos-config that referenced this issue Jun 12, 2022
@veprbl veprbl unpinned this issue Jul 7, 2022
thomaschrstnsn added a commit to thomaschrstnsn/dotfiles that referenced this issue Jul 15, 2022
@Artturin Artturin closed this as completed Mar 8, 2023
Infinidoge added a commit to Infinidoge/universe that referenced this issue Mar 30, 2023
Infinidoge added a commit to Infinidoge/universe that referenced this issue Mar 30, 2023
thomaschrstnsn added a commit to thomaschrstnsn/dotfiles that referenced this issue Mar 31, 2023
Infinidoge added a commit to Infinidoge/universe that referenced this issue Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet