Nixpkgs: `fetchGit` requires `git` as runtime dependency

Created on 13 Sep 2018  路  17Comments  路  Source: NixOS/nixpkgs

Issue description

nixos/nix#2419

nix already requires git to build, but it fails to evaluate anything fetchGit without git installed. Maybe git should be a runtime dependency?

Steps to reproduce

Install nix but not git, use fetchGit

Most helpful comment

This is intentional. git is not a hard dependency since it's only needed if you use fetchGit. Since Git is a sizeable dependency, we don't want to pull it in unconditionally. (Likewise for Mercurial).

All 17 comments

This is intentional. git is not a hard dependency since it's only needed if you use fetchGit. Since Git is a sizeable dependency, we don't want to pull it in unconditionally. (Likewise for Mercurial).

If we define correctness as "will the program work in more cases", then the existing situation is worse than the new situation w.r.t. correctness. As such, this can be classified as an optimization.

Performance optimizations (especially if they do not come with data and are breaking correctness) should be options that organizations can adopt on a case by case basis.

nix already requires git to build

does it?

I think we should then at least ship the NixOS installer with git installed. This would hide the impurity. Users shouldn't have failing builds because of missing dependencies.

We are not using fetchGit anywhere in nixpkgs. What builds in the installer should fail?

Users might use fetchGit in their configuration, for example in order to obtain packages from a nixpkgs fork.

This is intentional. git is not a hard dependency since it's only needed if you use fetchGit. Since Git is a sizeable dependency, we don't want to pull it in unconditionally. (Likewise for Mercurial).

This line of argument seems to throw the entire purpose and practicality of nix into question... Personally, I don't buy it, though. In my opinion, if nix doesn't want to support a pure dependency on git out of the box, it seems like fetchGit support should correspondingly be configured out by default.

Edit: To be clear, I'm sure you know that. I'm just trying to push back with a bit of idealism because there definitely is a way forward that is not a total compromise, it's "just" more work.

This wasn intentional so closing.

I ran into this issue several times when executing my nix expressions in different environments. Strange feeling since the whole purpose of using nix was to get rid of dependency issues. Now nix brings one in by itself. If fetchGit cannot be assumed working, why do the docs recommend it for pinning nixpkgs? Wouldn't it be better to avoid using it as much as possible?

Sorry for the naive question, but what is the workaround? At the moment I'm installing git first and then I add the package that uses fetchGit.

Installing git first seems to be the workaround. You could also install it globally on your system, in the nixos config.

The other alternative would be fetchTarball, which works at least with GitHub or flakes in future.

Tanks for the solutions. Unfortunately fetchTarball isn't an option for now. I'm fetching private repo from gitlab. When I install git, then switch and then add the derivation that uses fetchGit, it's working. I've hoped for only one switch and no global git.

Depending on what you are doing you can run this build inside a nix-shell that makes git available, it doesn't have to be globally installed first.

I'm building a nodejs server as a systemd service. This is what I import in my configuration.nix

{ config, pkgs, git, ... }:
let
  yarn2nix = pkgs.yarn2nix-moretea.override {
    nodejs = pkgs.nodejs-12_x;
    yarn = (pkgs.yarn.override { nodejs = pkgs.nodejs-12_x; });
  };
  my-nodejs-server = yarn2nix.mkYarnPackage {
    name = "my-nodejs-server";
    src = builtins.fetchGit {
      url = "https://gitlab.com/my-namespace/my-project.git";
      rev = "my-rev";
    };
  };
in
{
  systemd.services.my-nodejs-server = {
    serviceConfig = {
      ExecStart = "${pkgs.nodejs-12_x}/bin/node ${my-nodejs-server.outPath}/bin/my-bin";
      Restart = "always";
      RestartSec = "10s";
    };
    after = [ "network.target" ];
    wantedBy = [ "multi-user.target" ];
    environment.PORT = "4001";
  };

  environment.systemPackages = [ my-nodejs-server ];
}

@vidyu You could use fetchgit from nixpkgs instead of builtins.fetchGit. If you need ssh key you could override the derivation returned by fetchgit and add your other credentials: https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/fetchgit/default.nix

Thank you @Mic92 ! I had some problems finding the right sha256, but it's working like expected and I don't need to make two switches (one for git and one for the nodejs package).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sid-kap picture sid-kap  路  3Comments

teto picture teto  路  3Comments

domenkozar picture domenkozar  路  3Comments

edolstra picture edolstra  路  3Comments

copumpkin picture copumpkin  路  3Comments