From 5bb1f67568366fbb2402cf1110f116d74857c3f6 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 26 Aug 2022 21:48:50 +0200 Subject: [PATCH] git: add option to define store names for generated include files (#3171) This allows to use gitconfig/gitconfig-some-intent as store path suffixes for the texts. --- modules/programs/git.nix | 16 +++++++++++++--- tests/modules/programs/git/git-expected.conf | 3 +++ tests/modules/programs/git/git.nix | 9 ++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/modules/programs/git.nix b/modules/programs/git.nix index 7539ab82c..9b0d4c0d5 100644 --- a/modules/programs/git.nix +++ b/modules/programs/git.nix @@ -130,10 +130,20 @@ let . ''; }; - }; - config.path = mkIf (config.contents != { }) - (mkDefault (pkgs.writeText "contents" (gitToIni config.contents))); + contentSuffix = mkOption { + type = types.str; + default = "gitconfig"; + description = '' + Nix store name for the git configuration text file, + when generating the configuration text from nix options. + ''; + + }; + }; + config.path = mkIf (config.contents != { }) (mkDefault + (pkgs.writeText (hm.strings.storeFileName config.contentSuffix) + (gitToIni config.contents))); }); in { diff --git a/tests/modules/programs/git/git-expected.conf b/tests/modules/programs/git/git-expected.conf index fe258a0d3..ce1b22edf 100644 --- a/tests/modules/programs/git/git-expected.conf +++ b/tests/modules/programs/git/git-expected.conf @@ -56,3 +56,6 @@ [includeIf "gitdir:~/src/dir"] path = "@git_include_path@" + +[includeIf "gitdir:~/src/otherproject"] + path = "@git_named_include_path@" diff --git a/tests/modules/programs/git/git.nix b/tests/modules/programs/git/git.nix index 6c7320604..fb949be00 100644 --- a/tests/modules/programs/git/git.nix +++ b/tests/modules/programs/git/git.nix @@ -14,7 +14,9 @@ let substituteExpected = path: pkgs.substituteAll { src = path; - git_include_path = pkgs.writeText "contents" + git_include_path = pkgs.writeText "hm_gitconfig" + (builtins.readFile ./git-expected-include.conf); + git_named_include_path = pkgs.writeText "hm_gitconfigwork" (builtins.readFile ./git-expected-include.conf); }; @@ -46,6 +48,11 @@ in { condition = "gitdir:~/src/dir"; contents = gitInclude; } + { + condition = "gitdir:~/src/otherproject"; + contents = gitInclude; + contentSuffix = "gitconfig-work"; + } ]; signing = { gpgPath = "path-to-gpg";