config: add a `gitConfig`/`gitConfigFile` option

Adds a `gitConfig` option (and `gitConfigFile`), to set a default
`gitConfigFile` argument for `fetchgit`.

Changed files
+50 -11
pkgs
build-support
top-level
+2 -1
pkgs/build-support/fetchgit/default.nix
···
{
+
config,
lib,
stdenvNoCC,
writeText,
···
# make this subdirectory the root of the result
rootDir ? "",
# GIT_CONFIG_GLOBAL (as a file)
-
gitConfigFile ? null,
+
gitConfigFile ? config.gitConfigFile,
}:
/*
+14 -10
pkgs/build-support/fetchgit/tests.nix
···
cacert,
nix,
closureInfo,
-
lib,
...
}:
{
···
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=";
+
};
}
+34
pkgs/top-level/config.nix
···
'';
};
+
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";
};