diff options
-rw-r--r-- | pkgs/build-support/fetchbitbucket/default.nix | 10 | ||||
-rw-r--r-- | pkgs/build-support/fetchgithub/default.nix | 33 | ||||
-rw-r--r-- | pkgs/build-support/fetchgitlab/default.nix | 10 | ||||
-rw-r--r-- | pkgs/build-support/fetchrepoorcz/default.nix | 10 | ||||
-rw-r--r-- | pkgs/build-support/fetchsavannah/default.nix | 10 | ||||
-rw-r--r-- | pkgs/top-level/all-packages.nix | 81 |
6 files changed, 82 insertions, 72 deletions
diff --git a/pkgs/build-support/fetchbitbucket/default.nix b/pkgs/build-support/fetchbitbucket/default.nix new file mode 100644 index 000000000000..a99f72e9eaa7 --- /dev/null +++ b/pkgs/build-support/fetchbitbucket/default.nix @@ -0,0 +1,10 @@ +{ fetchzip }: + +{ owner, repo, rev, name ? "source" +, ... # For hash agility +}@args: fetchzip ({ + inherit name; + url = "https://bitbucket.org/${owner}/${repo}/get/${rev}.tar.gz"; + meta.homepage = "https://bitbucket.org/${owner}/${repo}/"; + extraPostFetch = ''rm -f "$out"/.hg_archival.txt''; # impure file; see #12002 +} // removeAttrs args [ "owner" "repo" "rev" ]) // { inherit rev; } diff --git a/pkgs/build-support/fetchgithub/default.nix b/pkgs/build-support/fetchgithub/default.nix new file mode 100644 index 000000000000..66671dd0a6ae --- /dev/null +++ b/pkgs/build-support/fetchgithub/default.nix @@ -0,0 +1,33 @@ +{ lib, fetchgit, fetchzip }: + +{ owner, repo, rev, name ? "source" +, fetchSubmodules ? false, private ? false +, githubBase ? "github.com", varPrefix ? null +, ... # For hash agility +}@args: assert private -> !fetchSubmodules; +let + baseUrl = "https://${githubBase}/${owner}/${repo}"; + passthruAttrs = removeAttrs args [ "owner" "repo" "rev" "fetchSubmodules" "private" "githubBase" "varPrefix" ]; + varBase = "NIX${if varPrefix == null then "" else "_${varPrefix}"}_GITHUB_PRIVATE_"; + # We prefer fetchzip in cases we don't need submodules as the hash + # is more stable in that case. + fetcher = if fetchSubmodules then fetchgit else fetchzip; + privateAttrs = lib.optionalAttrs private { + netrcPhase = '' + if [ -z "''$${varBase}USERNAME" -o -z "''$${varBase}PASSWORD" ]; then + echo "Error: Private fetchFromGitHub requires the nix building process (nix-daemon in multi user mode) to have the ${varBase}USERNAME and ${varBase}PASSWORD env vars set." >&2 + exit 1 + fi + cat > netrc <<EOF + machine ${githubBase} + login ''$${varBase}USERNAME + password ''$${varBase}PASSWORD + EOF + ''; + netrcImpureEnvVars = [ "${varBase}USERNAME" "${varBase}PASSWORD" ]; + }; + fetcherArgs = (if fetchSubmodules + then { inherit rev fetchSubmodules; url = "${baseUrl}.git"; } + else ({ url = "${baseUrl}/archive/${rev}.tar.gz"; } // privateAttrs) + ) // passthruAttrs // { inherit name; }; +in fetcher fetcherArgs // { meta.homepage = baseUrl; inherit rev; } diff --git a/pkgs/build-support/fetchgitlab/default.nix b/pkgs/build-support/fetchgitlab/default.nix new file mode 100644 index 000000000000..be110cf8393e --- /dev/null +++ b/pkgs/build-support/fetchgitlab/default.nix @@ -0,0 +1,10 @@ +{ fetchzip, lib }: + +# gitlab example +{ owner, repo, rev, domain ? "gitlab.com", name ? "source", group ? null +, ... # For hash agility +}@args: fetchzip ({ + inherit name; + url = "https://${domain}/api/v4/projects/${lib.optionalString (group != null) "${lib.replaceStrings ["."] ["%2E"] group}%2F"}${lib.replaceStrings ["."] ["%2E"] owner}%2F${lib.replaceStrings ["."] ["%2E"] repo}/repository/archive.tar.gz?sha=${rev}"; + meta.homepage = "https://${domain}/${lib.optionalString (group != null) "${group}/"}${owner}/${repo}/"; +} // removeAttrs args [ "domain" "owner" "group" "repo" "rev" ]) // { inherit rev; } diff --git a/pkgs/build-support/fetchrepoorcz/default.nix b/pkgs/build-support/fetchrepoorcz/default.nix new file mode 100644 index 000000000000..3ac7cace0dcf --- /dev/null +++ b/pkgs/build-support/fetchrepoorcz/default.nix @@ -0,0 +1,10 @@ +{ fetchzip }: + +# gitweb example, snapshot support is optional in gitweb +{ repo, rev, name ? "source" +, ... # For hash agility +}@args: fetchzip ({ + inherit name; + url = "https://repo.or.cz/${repo}.git/snapshot/${rev}.tar.gz"; + meta.homepage = "https://repo.or.cz/${repo}.git/"; +} // removeAttrs args [ "repo" "rev" ]) // { inherit rev; } diff --git a/pkgs/build-support/fetchsavannah/default.nix b/pkgs/build-support/fetchsavannah/default.nix new file mode 100644 index 000000000000..994922a58679 --- /dev/null +++ b/pkgs/build-support/fetchsavannah/default.nix @@ -0,0 +1,10 @@ +{ fetchzip }: + +# cgit example, snapshot support is optional in cgit +{ repo, rev, name ? "source" +, ... # For hash agility +}@args: fetchzip ({ + inherit name; + url = "https://git.savannah.gnu.org/cgit/${repo}.git/snapshot/${repo}-${rev}.tar.gz"; + meta.homepage = "https://git.savannah.gnu.org/cgit/${repo}.git/"; +} // removeAttrs args [ "repo" "rev" ]) // { inherit rev; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index efe9dbd2e629..da1f8a1533e1 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -261,78 +261,15 @@ in fetchCrate = callPackage ../build-support/rust/fetchcrate.nix { }; - fetchFromGitHub = { - owner, repo, rev, name ? "source", - fetchSubmodules ? false, private ? false, - githubBase ? "github.com", varPrefix ? null, - ... # For hash agility - }@args: assert private -> !fetchSubmodules; - let - baseUrl = "https://${githubBase}/${owner}/${repo}"; - passthruAttrs = removeAttrs args [ "owner" "repo" "rev" "fetchSubmodules" "private" "githubBase" "varPrefix" ]; - varBase = "NIX${if varPrefix == null then "" else "_${varPrefix}"}_GITHUB_PRIVATE_"; - # We prefer fetchzip in cases we don't need submodules as the hash - # is more stable in that case. - fetcher = if fetchSubmodules then fetchgit else fetchzip; - privateAttrs = lib.optionalAttrs private { - netrcPhase = '' - if [ -z "''$${varBase}USERNAME" -o -z "''$${varBase}PASSWORD" ]; then - echo "Error: Private fetchFromGitHub requires the nix building process (nix-daemon in multi user mode) to have the ${varBase}USERNAME and ${varBase}PASSWORD env vars set." >&2 - exit 1 - fi - cat > netrc <<EOF - machine ${githubBase} - login ''$${varBase}USERNAME - password ''$${varBase}PASSWORD - EOF - ''; - netrcImpureEnvVars = [ "${varBase}USERNAME" "${varBase}PASSWORD" ]; - }; - fetcherArgs = (if fetchSubmodules - then { inherit rev fetchSubmodules; url = "${baseUrl}.git"; } - else ({ url = "${baseUrl}/archive/${rev}.tar.gz"; } // privateAttrs) - ) // passthruAttrs // { inherit name; }; - in fetcher fetcherArgs // { meta.homepage = baseUrl; inherit rev; }; - - fetchFromBitbucket = { - owner, repo, rev, name ? "source", - ... # For hash agility - }@args: fetchzip ({ - inherit name; - url = "https://bitbucket.org/${owner}/${repo}/get/${rev}.tar.gz"; - meta.homepage = "https://bitbucket.org/${owner}/${repo}/"; - extraPostFetch = ''rm -f "$out"/.hg_archival.txt''; # impure file; see #12002 - } // removeAttrs args [ "owner" "repo" "rev" ]) // { inherit rev; }; - - # cgit example, snapshot support is optional in cgit - fetchFromSavannah = { - repo, rev, name ? "source", - ... # For hash agility - }@args: fetchzip ({ - inherit name; - url = "https://git.savannah.gnu.org/cgit/${repo}.git/snapshot/${repo}-${rev}.tar.gz"; - meta.homepage = "https://git.savannah.gnu.org/cgit/${repo}.git/"; - } // removeAttrs args [ "repo" "rev" ]) // { inherit rev; }; - - # gitlab example - fetchFromGitLab = { - owner, repo, rev, domain ? "gitlab.com", name ? "source", group ? null, - ... # For hash agility - }@args: fetchzip ({ - inherit name; - url = "https://${domain}/api/v4/projects/${lib.optionalString (group != null) "${lib.replaceStrings ["."] ["%2E"] group}%2F"}${lib.replaceStrings ["."] ["%2E"] owner}%2F${lib.replaceStrings ["."] ["%2E"] repo}/repository/archive.tar.gz?sha=${rev}"; - meta.homepage = "https://${domain}/${lib.optionalString (group != null) "${group}/"}${owner}/${repo}/"; - } // removeAttrs args [ "domain" "owner" "group" "repo" "rev" ]) // { inherit rev; }; - - # gitweb example, snapshot support is optional in gitweb - fetchFromRepoOrCz = { - repo, rev, name ? "source", - ... # For hash agility - }@args: fetchzip ({ - inherit name; - url = "https://repo.or.cz/${repo}.git/snapshot/${rev}.tar.gz"; - meta.homepage = "https://repo.or.cz/${repo}.git/"; - } // removeAttrs args [ "repo" "rev" ]) // { inherit rev; }; + fetchFromGitHub = callPackage ../build-support/fetchgithub {}; + + fetchFromBitbucket = callPackage ../build-support/fetchbitbucket {}; + + fetchFromSavannah = callPackage ../build-support/fetchsavannah {}; + + fetchFromGitLab = callPackage ../build-support/fetchgitlab {}; + + fetchFromRepoOrCz = callPackage ../build-support/fetchrepoorcz {}; fetchNuGet = callPackage ../build-support/fetchnuget { }; buildDotnetPackage = callPackage ../build-support/build-dotnet-package { }; |