From 6f53c067482743fd68a5beceeb1205fab0ebe4c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Wed, 15 Sep 2021 16:17:05 +0200 Subject: [PATCH 1/3] fetchgit: add support for netrc file through impure NIX_GIT_SSL_CAINFO env --- pkgs/build-support/fetchgit/default.nix | 16 ++++++++++++++-- pkgs/build-support/fetchgit/nix-prefetch-git | 4 ++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 3222866dc781..c139030ea973 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -21,6 +21,11 @@ in postFetch ? "" , preferLocalBuild ? true , fetchLFS ? false +, # Shell code to build a netrc file for BASIC auth + netrcPhase ? null +, # Impure env vars (https://nixos.org/nix/manual/#sec-advanced-attributes) + # needed for netrcPhase + netrcImpureEnvVars ? [] }: /* NOTE: @@ -64,10 +69,17 @@ stdenvNoCC.mkDerivation { inherit url rev leaveDotGit fetchLFS fetchSubmodules deepClone branchName postFetch; + postHook = if netrcPhase == null then null else '' + ${netrcPhase} + # required that git uses the netrc file + mv {,.}netrc + export HOME=$PWD + ''; + GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt"; - impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ - "GIT_PROXY_COMMAND" "SOCKS_SERVER" + impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ netrcImpureEnvVars ++ [ + "GIT_PROXY_COMMAND" "NIX_GIT_SSL_CAINFO" "SOCKS_SERVER" ]; inherit preferLocalBuild; diff --git a/pkgs/build-support/fetchgit/nix-prefetch-git b/pkgs/build-support/fetchgit/nix-prefetch-git index 6e869ab5e437..10b402de6145 100755 --- a/pkgs/build-support/fetchgit/nix-prefetch-git +++ b/pkgs/build-support/fetchgit/nix-prefetch-git @@ -17,6 +17,10 @@ branchName=$NIX_PREFETCH_GIT_BRANCH_NAME out=${out:-} http_proxy=${http_proxy:-} +# allow overwritting cacert's ca-bundle.crt with a custom one +# this can be done by setting NIX_GIT_SSL_CAINFO and NIX_SSL_CERT_FILE enviroment variables for the nix-daemon +GIT_SSL_CAINFO=${NIX_GIT_SSL_CAINFO:-$GIT_SSL_CAINFO} + # populated by clone_user_rev() fullRev= humanReadableRev= From b9f8421d48b77f5982008703375a0d8850b30ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Wed, 15 Sep 2021 16:17:30 +0200 Subject: [PATCH 2/3] fetchgithub: allow private repos to use fetchgit --- pkgs/build-support/fetchgithub/default.nix | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkgs/build-support/fetchgithub/default.nix b/pkgs/build-support/fetchgithub/default.nix index 3f355d10f8a1..91ffe4c6d8ed 100644 --- a/pkgs/build-support/fetchgithub/default.nix +++ b/pkgs/build-support/fetchgithub/default.nix @@ -32,10 +32,8 @@ let then { inherit rev deepClone fetchSubmodules; url = "${baseUrl}.git"; } // lib.optionalAttrs (leaveDotGit != null) { inherit leaveDotGit; } - else ({ url = "${baseUrl}/archive/${rev}.tar.gz"; } // privateAttrs) - ) // passthruAttrs // { inherit name; }; + else { url = "${baseUrl}/archive/${rev}.tar.gz"; } + ) // privateAttrs // passthruAttrs // { inherit name; }; in -assert private -> !useFetchGit; - fetcher fetcherArgs // { meta.homepage = baseUrl; inherit rev; } From 00dc3dcf8bfb3d7806fefa83e1e65d46cd6b5e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sun, 26 Sep 2021 15:41:34 +0200 Subject: [PATCH 3/3] fetchFromGitHub: allow forcing fetchGit --- pkgs/build-support/fetchgithub/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/fetchgithub/default.nix b/pkgs/build-support/fetchgithub/default.nix index 91ffe4c6d8ed..ea95bbb47931 100644 --- a/pkgs/build-support/fetchgithub/default.nix +++ b/pkgs/build-support/fetchgithub/default.nix @@ -2,7 +2,7 @@ { owner, repo, rev, name ? "source" , fetchSubmodules ? false, leaveDotGit ? null -, deepClone ? false, private ? false +, deepClone ? false, private ? false, forceFetchGit ? false , githubBase ? "github.com", varPrefix ? null , ... # For hash agility }@args: @@ -10,7 +10,7 @@ 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_"; - useFetchGit = fetchSubmodules || (leaveDotGit == true) || deepClone; + useFetchGit = fetchSubmodules || (leaveDotGit == true) || deepClone || forceFetchGit; # We prefer fetchzip in cases we don't need submodules as the hash # is more stable in that case. fetcher = if useFetchGit then fetchgit else fetchzip;