config: add a gitConfig/gitConfigFile option
Adds a `gitConfig` option (and `gitConfigFile`), to set a default `gitConfigFile` argument for `fetchgit`.
This commit is contained in:
committed by
Silvan Mosberger
parent
296399ec68
commit
80d9975bd4
@@ -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,
|
||||
}:
|
||||
|
||||
/*
|
||||
|
||||
@@ -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=";
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user