Nixos-rebuild switch fails without git installed (with flake)

So, I’m new to nixos and I’m running a configuration based on nix-starter-configs. My config lives in a git repository at /etc/nix-config based on the standard nix-start-configs template.

I uninstalled git by removing it from my config and rebuilding. Now I want to reinstalled git, so I added the git package back to my config - but nixos-rebuild switch is failing:
$ sudo nixos-rebuild switch --flake .
error: getting the HEAD of the Git tree ‘/etc/nix-config’ failed with exit code 1:
error: executing ‘git’: No such file or directory

So, did I just bork my system by removing git and that was a bad idea? Is the best way to recover to rebuild from a config located elsewhere? Is this expected behavior or a bug?

reboot to a previously build generation

1 Like

Yup. I did reboot to a previous generation and that got me out of it.

What did I do wrong? Is it simply not supported to uninstall git?

I don’t have Git installed in my environment on my servers. When I need to run nixos-rebuild manually, I use nix shell nixpkgs#git to get a shell with Git, then I run nixos-rebuild like normal.


The execution of nix apparently depends on the external git program. A little bit weired to me, maybe we don’t have a nice libgit currently?

My naïve reading of this is that the nix tool depends on git being available, so it should reference that directly. It shouldn’t pick it up from $PATH either – how do we know that’s the right version of git? So yeah sounds buggy to me.

1 Like

It does depends on git, not very reasonable to me.

It does optionally depend on it if you want to put it like that.

Nix doesn’t require git to be available unless you use flakes (with a git+* schema) or builtins.fetchGit in non-experimental nix.

The same issue exists for curl and builtins.fetchurl and it’s friends.

Though this dependency is met by “accident”.

Edit and PS:

The very same problem as for git exists for any other supported VCS.

Do you want to include them all and explode the closure by magnitudes?

I prefer the “optional” dependencies here.

1 Like

I am using flakes.

Curl seems a little different - I would expect that dependency is met explicitly.

If git and/or other VCS systems are truly optional, then it feels like this should ‘fail’ gracefully. So, like, if git isn’t present it should fail to do anything it would do with git - but the core rebuild functionality should still work. Right?

1 Like

What should it build? It requires git to be able to even access the flake.

I agree though, the error could be improved to something “git is not available, please make sure it is in PATH to proceed”

1 Like

Couldn’t nix bootstrap the required “optional” packages on demand? It’s a build system/package manager, after all.

Essentially, what I am suggesting is that you wouldn’t get git (or other VCS packages) as direct dependencies. Instead, the first time nix needs to use git, it does something along the lines of

nix build "${revision}.tar.gz"#git

where revision is either the same nixpkgs revision that was used to build the current nix package or maybe some hardcoded, well-known revision in cases, where nix wasn’t built from the official nixpkgs.

1 Like

No, please do not hardcode nixpkgs into it…

1 Like

It doesn’t have to be nixpkgs specifically. We just need a URL to a downloadable source that can provide git. A fixed revision of nixpkgs makes sense as a default value, but it should be possible to configure it during build (and maybe even at runtime via a config option). You can even leave null as a special value meaning "just use the version on PATH" like it does today.