Skip to content

Commit

Permalink
lib, treewide: use repoRevToName in fetchgit and fetchhg, homog…
Browse files Browse the repository at this point in the history
…enize `name`s in `fetchsvn`

In effect, this homogenizes derivation names produced by all `fetch*` functions
so that switching from e.g. `fetchFromGitHub` to `fetchgit` would be a noop
(assuming the content hash does not change, which is not always the case for
`fetchFromGitHub` since GitHub uses `git archive` internally and `fetchgit`
does not) with both the default `config.nameSourcesPrettily` setting and with
`config.nameSourcesPrettily = true`.
  • Loading branch information
oxij committed Jun 5, 2024
1 parent a09a1e7 commit 8749da1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
11 changes: 2 additions & 9 deletions pkgs/build-support/fetchgit/default.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
{lib, stdenvNoCC, git, git-lfs, cacert}:

let
urlToName = url: rev: let
shortRev = lib.sources.shortRev rev;
appendShort = lib.optionalString ((builtins.match "[a-f0-9]*" rev) != null) "-${shortRev}";
in "${lib.sources.urlToName url}${appendShort}";
in
{lib, repoRevToNameMaybe, stdenvNoCC, git, git-lfs, cacert}:

lib.makeOverridable (
{ url, rev ? "HEAD"
, name ? urlToName url rev
, name ? repoRevToNameMaybe url rev "git"
, sha256 ? "", hash ? "", leaveDotGit ? deepClone
, fetchSubmodules ? true, deepClone ? false
, branchName ? null
Expand Down
11 changes: 6 additions & 5 deletions pkgs/build-support/fetchhg/default.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{ lib, stdenvNoCC, mercurial }:
{ name ? null
, url
{ lib, repoRevToNameMaybe, stdenvNoCC, mercurial }:
{ url
, rev ? null
, name ? repoRevToNameMaybe url rev "hg"
, sha256 ? null
, hash ? null
, fetchSubrepos ? false
, preferLocalBuild ? true }:
, preferLocalBuild ? true
}:

if hash != null && sha256 != null then
throw "Only one of sha256 or hash can be set"
else
# TODO: statically check if mercurial as the https support if the url starts woth https.
stdenvNoCC.mkDerivation {
name = "hg-archive" + (lib.optionalString (name != null) "-${name}");
inherit name;
builder = ./builder.sh;
nativeBuildInputs = [mercurial];

Expand Down
7 changes: 5 additions & 2 deletions pkgs/build-support/fetchsvn/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, stdenvNoCC, buildPackages
{ lib, config, stdenvNoCC, buildPackages
, subversion, glibcLocales, sshSupport ? true, openssh ? null
}:

Expand All @@ -17,7 +17,10 @@ let
else if elemAt path 1 == "tags" then "${elemAt path 2}-${head path}"
# ../repo (no trunk) -> repo
else head path;
in "${repoName}-r${toString rev}";
pretty = config.nameSourcesPrettily;
suffix = lib.optionalString (pretty == "full") "-svn";
in if pretty == false then "source"
else "${repoName}-r${toString rev}${suffix}-source";
in

{ url, rev ? "HEAD"
Expand Down

0 comments on commit 8749da1

Please sign in to comment.