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

fetchGit requires git as runtime dependency #46603

Closed
yorickvP opened this issue Sep 13, 2018 · 18 comments
Closed

fetchGit requires git as runtime dependency #46603

yorickvP opened this issue Sep 13, 2018 · 18 comments

Comments

@yorickvP
Copy link
Contributor

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

@edolstra
Copy link
Member

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).

@coretemp
Copy link
Contributor

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.

@lheckemann
Copy link
Member

nix already requires git to build

does it?

@haslersn
Copy link
Contributor

haslersn commented Sep 15, 2018

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.

@Mic92
Copy link
Member

Mic92 commented Sep 15, 2018

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

@haslersn
Copy link
Contributor

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

@clhodapp
Copy link
Contributor

clhodapp commented Feb 4, 2019

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.

fricklerhandwerk added a commit to fricklerhandwerk/settings that referenced this issue Jun 24, 2019
there seems to be a hidden dependency on `git` in `builtins.fetchGit`:
<NixOS/nixpkgs#46603>

<NixOS/nixpkgs#46603 (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).

> This line of argument seems to throw the entire purpose and
  practicality of nix into question...

I completely agree.
fricklerhandwerk added a commit to fricklerhandwerk/settings that referenced this issue Jun 25, 2019
there seems to be a hidden dependency on `git` in `builtins.fetchGit`:
<NixOS/nixpkgs#46603>

<NixOS/nixpkgs#46603 (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).

> This line of argument seems to throw the entire purpose and
  practicality of nix into question...

I completely agree.
fricklerhandwerk added a commit to fricklerhandwerk/settings that referenced this issue Jun 25, 2019
there seems to be a hidden dependency on `git` in `builtins.fetchGit`:
<NixOS/nixpkgs#46603>

<NixOS/nixpkgs#46603 (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).

> This line of argument seems to throw the entire purpose and
  practicality of nix into question...

I completely agree.
@FRidh
Copy link
Member

FRidh commented Sep 15, 2019

This wasn intentional so closing.

@FRidh FRidh closed this as completed Sep 15, 2019
@DavHau
Copy link
Member

DavHau commented Mar 25, 2020

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?

@vidyu
Copy link

vidyu commented Apr 25, 2020

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.

@yorickvP
Copy link
Contributor Author

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

@Mic92
Copy link
Member

Mic92 commented Apr 27, 2020

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

@vidyu
Copy link

vidyu commented May 3, 2020

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.

@LnL7
Copy link
Member

LnL7 commented May 3, 2020

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.

@vidyu
Copy link

vidyu commented May 3, 2020

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 ];
}

@Mic92
Copy link
Member

Mic92 commented May 3, 2020

@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

@vidyu
Copy link

vidyu commented May 4, 2020

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).

@lfdominguez
Copy link

Well then... you have a bultins fetchGit that's not work?? great...

fricklerhandwerk added a commit to fricklerhandwerk/settings that referenced this issue Jun 17, 2023
there seems to be a hidden dependency on `git` in `builtins.fetchGit`:
<NixOS/nixpkgs#46603>

<NixOS/nixpkgs#46603 (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).

> This line of argument seems to throw the entire purpose and
  practicality of nix into question...

I completely agree.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests