diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 37a8c50eb928..45c7599b1c74 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -1,4 +1,5 @@ { + config, lib, stdenvNoCC, writeText, @@ -66,7 +67,7 @@ lib.makeOverridable ( # make this subdirectory the root of the result rootDir ? "", # GIT_CONFIG_GLOBAL (as a file) - gitConfigFile ? null, + gitConfigFile ? config.gitConfigFile, }: /* diff --git a/pkgs/build-support/fetchgit/tests.nix b/pkgs/build-support/fetchgit/tests.nix index a39b8ad1bd93..9ccb3ff3058b 100644 --- a/pkgs/build-support/fetchgit/tests.nix +++ b/pkgs/build-support/fetchgit/tests.nix @@ -7,7 +7,6 @@ cacert, nix, closureInfo, - lib, ... }: { @@ -196,13 +195,18 @@ hash = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY="; }; - withGitConfig = testers.invalidateFetcherByDrvHash fetchgit { - name = "fetchgit-with-config"; - url = "https://doesntexist.forsure/NixOS/nix"; - rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a"; - sha256 = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY="; - gitConfigFile = builtins.toFile "gitconfig" (lib.generators.toGitINI { - url."https://github.com".insteadOf = "https://doesntexist.forsure"; - }); - }; + withGitConfig = + let + pkgs = import ../../.. { + config.gitConfig = { + url."https://github.com".insteadOf = "https://doesntexist.forsure"; + }; + }; + in + pkgs.testers.invalidateFetcherByDrvHash pkgs.fetchgit { + name = "fetchgit-with-config"; + url = "https://doesntexist.forsure/NixOS/nix"; + rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a"; + sha256 = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY="; + }; } diff --git a/pkgs/top-level/config.nix b/pkgs/top-level/config.nix index c3c78e9d3e80..e969e1be3a36 100644 --- a/pkgs/top-level/config.nix +++ b/pkgs/top-level/config.nix @@ -105,6 +105,40 @@ let ''; }; + gitConfig = mkOption { + type = types.attrsOf (types.attrsOf types.anything); + description = '' + The default [git configuration](https://git-scm.com/docs/git-config#_variables) for all [`pkgs.fetchgit`](#fetchgit) calls. + + Among many other potential uses, this can be used to override URLs to point to local mirrors. + + Changing this will not cause any rebuilds because `pkgs.fetchgit` produces a [fixed-output derivation](https://nix.dev/manual/nix/stable/glossary.html?highlight=fixed-output%20derivation#gloss-fixed-output-derivation). + + To set the configuration file directly, use the [`gitConfigFile`](#opt-gitConfigFile) option instead. + + To set the configuration file for individual calls, use `fetchurl { gitConfigFile = "..."; }`. + ''; + default = { }; + example = { + url."https://my-github-mirror.local".insteadOf = [ "https://github.com" ]; + }; + }; + + # A rendered version of gitConfig that can be reused by all pkgs.fetchgit calls + gitConfigFile = mkOption { + type = types.nullOr types.path; + description = '' + A path to a [git configuration](https://git-scm.com/docs/git-config#_variables) file, to be used for all [`pkgs.fetchgit`](#fetchgit) calls. + + This overrides the [`gitConfig`](#opt-gitConfig) option, see its documentation for more details. + ''; + default = + if config.gitConfig != { } then + builtins.toFile "gitconfig" (lib.generators.toGitINI config.gitConfig) + else + null; + }; + doCheckByDefault = mkMassRebuild { feature = "run `checkPhase` by default"; };