Skip to content

builtins.fetchGit’s return value should have a url attribute #11222

Open
@Jayman2000

Description

Is your feature request related to a problem? Please describe.

  1. Create a file named package.nix that contains this:

    let
      pkgs = import <nixpkgs> { };
      url = "https://github.com/commonmark/cmark";
    in
    
    pkgs.stdenv.mkDerivation (finalAttrs: {
      pname = "cmark";
      version = "0.30.3";
      src = builtins.fetchGit {
        inherit url;
        ref = "refs/tags/${finalAttrs.version}";
      };
      nativeBuildInputs = [ pkgs.cmake ];
    })
  2. Create a file named default.nix that contains this:

    { }:
    
    {
      cmark = import ./package.nix;
    }
  3. Try running nix-update:

    nix-shell -p nix-update --run 'nix-update cmark'

    It will fail with this error:

    nix_update.errors.UpdateError: Could not find a url in the derivations src attribute
    

Describe the solution you'd like
It would be nice if the return value of builtins.fetchGit had a url attribute. That would allow downstream processors of Nix expressions to do things with the Git repo’s URL.

Describe alternatives you've considered
Here’s a workaround:

let
  pkgs = import <nixpkgs> { };
  url = "https://github.com/commonmark/cmark";
in

pkgs.stdenv.mkDerivation (finalAttrs: {
  pname = "cmark";
  version = "0.30.3";
  src = (builtins.fetchGit {
    inherit url;
    ref = "refs/tags/${finalAttrs.version}";
  }) // {
    inherit url;
  };
  nativeBuildInputs = [ pkgs.cmake ];
})

Additional context
I’m currently working on a nixpkgs PR that’s related to vcpkg. In order for certain features of vcpkg to work properly, we need to know the commit hash for the version of vcpkg that we’re building. I proposed using builtins.fetchGit for this purpose because its return value has a rev attribute that contains the commit hash. Another contributor was concerned that automatic updates might stop working if we switched to builtins.fetchGit. I’m submitting this feature request because I want automatic updates to work regardless of whether or not we’re using builtins.fetchGit.

Priorities

Add 👍 to issues you find important.

Metadata

Assignees

No one assigned

    Labels

    featureFeature request or proposalfetchingNetworking with the outside (non-Nix) world, input locking

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions