Skip to content

Commit

Permalink
Merge pull request #7973 from oxij/fetchurl-meta
Browse files Browse the repository at this point in the history
fetchurl: allow adding meta info; fetchFrom*: add meta.homepage
  • Loading branch information
jagajaga committed May 25, 2015
2 parents 4835763 + bdf32ed commit 8981061
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions pkgs/build-support/fetchurl/default.nix
Expand Up @@ -76,6 +76,9 @@ in
, # If set, don't download the file, but write a list of all possible
# URLs (resulting from resolving mirror:// URLs) to $out.
showURLs ? false

, # Meta information, if any.
meta ? {}
}:

assert builtins.isList urls;
Expand Down Expand Up @@ -120,4 +123,6 @@ if (!hasHash) then throw "Specify hash for fetchurl fixed-output derivation: ${s
# Doing the download on a remote machine just duplicates network
# traffic, so don't do that.
preferLocalBuild = true;

inherit meta;
}
15 changes: 9 additions & 6 deletions pkgs/top-level/all-packages.nix
Expand Up @@ -370,40 +370,43 @@ let
fetchzip = import ../build-support/fetchzip { inherit lib fetchurl unzip; };

fetchFromGitHub = { owner, repo, rev, sha256, name ? "${repo}-${rev}-src" }: fetchzip {
inherit name;
inherit name sha256;
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
inherit sha256;
meta.homepage = "https://github.com/${owner}/${repo}/";
};

fetchFromBitbucket = { owner, repo, rev, sha256, name ? "${repo}-${rev}-src" }: fetchzip {
inherit name;
inherit name sha256;
url = "https://bitbucket.org/${owner}/${repo}/get/${rev}.tar.gz";
inherit sha256;
meta.homepage = "https://bitbucket.org/${owner}/${repo}/";
};

# gitorious example
fetchFromGitorious = { owner, repo, rev, sha256, name ? "${repo}-${rev}-src" }: fetchzip {
inherit name;
inherit name sha256;
url = "https://gitorious.org/${owner}/${repo}/archive/${rev}.tar.gz";
inherit sha256;
meta.homepage = "https://gitorious.org/${owner}/${repo}/";
};

# cgit example, snapshot support is optional in cgit
fetchFromSavannah = { repo, rev, sha256, name ? "${repo}-${rev}-src" }: fetchzip {
inherit name sha256;
url = "http://git.savannah.gnu.org/cgit/${repo}.git/snapshot/${repo}-${rev}.tar.gz";
meta.homepage = "http://git.savannah.gnu.org/cgit/${repo}.git/";
};

# gitlab example
fetchFromGitLab = { owner, repo, rev, sha256, name ? "${repo}-${rev}-src" }: fetchzip {
inherit name sha256;
url = "https://gitlab.com/${owner}/${repo}/repository/archive.tar.gz?ref=${rev}";
meta.homepage = "https://gitlab.com/${owner}/${repo}/";
};

# gitweb example, snapshot support is optional in gitweb
fetchFromRepoOrCz = { repo, rev, sha256, name ? "${repo}-${rev}-src" }: fetchzip {
inherit name sha256;
url = "http://repo.or.cz/${repo}.git/snapshot/${rev}.tar.gz";
meta.homepage = "http://repo.or.cz/${repo}.git/";
};

resolveMirrorURLs = {url}: fetchurl {
Expand Down

8 comments on commit 8981061

@aszlig
Copy link
Member

@aszlig aszlig commented on 8981061 May 28, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing something, but doesn't this only add the meta attribute to the src attribute/derivation and not the resulting derivation of package itself (at least I haven't found something where this is properly propagated)? So you still need to use something like:

stdenv.mkDerivation rec {
  name = "foo";
  src = fetchFromGitHub ...;
  meta = {
    inherit (src.meta) homepage;
    description = "blah";
  };
}

To avoid this we might need to modify the generic stdenv to pass the meta info from the src attribute (if it exists) to the resulting derivation and also allow it to get overridden by mkDerivation meta attributes (because it's not always the case that the project's homepage is the project page of the various hosters).

@aszlig
Copy link
Member

@aszlig aszlig commented on 8981061 May 28, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, never mind, the pull request and commit message states this, but the post in the mailing list does not.

@jagajaga
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cc @oxij

@peti
Copy link
Member

@peti peti commented on 8981061 May 28, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, this extension goes only half the way precisely because it doesn't add meta to the generated derivation. We'd need mkGithubDerivation just like we have fetchFromGitHub to ensure that meta is populated with meaningful default values. Once you have that, however, the need for src providing those defaults kind-of goes away, no?

@vcunat
Copy link
Member

@vcunat vcunat commented on 8981061 May 28, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it's worth using mkGithubDerivation instead of mkDerivation just to avoid line inherit (src.meta) homepage.

@peti
Copy link
Member

@peti peti commented on 8981061 May 28, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd get all the benefits you'd get from using fetchFromGitHub, and you'd also get an automatic meta.homepage url. Personally, I'd rather have mkGitHubDerivation and specify no fetchurl at all than having mkDerivation and fetchFromGitHub. Just my 2 cents ...

@edolstra
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think mkGitHubDerivation is a good idea because it's not compositional - we'd also need a buildGitHubPerlPackage, buildGitHubPythonPackage and so on.

@vcunat
Copy link
Member

@vcunat vcunat commented on 8981061 May 28, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get compositional, we could have it just return an augmented attrset, e.g.:

stdenv.mkDerivation (githubSomeGoodName {
    # attributes as in fetchFromGithHub now
  }
  {
    # rest of attributes that are just automatically extended by ``meta.homepage`` and ``src``
  }
)

Please sign in to comment.