From 6da88339f53f72eed62dedfbfb2e33acd0aa16da Mon Sep 17 00:00:00 2001 From: Mario Rodas Date: Tue, 29 Jan 2019 06:33:10 -0500 Subject: [PATCH] git: allow contents in git.includes --- modules/programs/git.nix | 18 ++++++++++++++--- tests/modules/programs/git-expected.conf | 3 +++ tests/modules/programs/git.nix | 25 ++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/modules/programs/git.nix b/modules/programs/git.nix index 1abf56281..71d79b019 100644 --- a/modules/programs/git.nix +++ b/modules/programs/git.nix @@ -34,7 +34,7 @@ let }; }; - includeModule = types.submodule { + includeModule = types.submodule ({ config, ... }: { options = { condition = mkOption { type = types.nullOr types.str; @@ -50,11 +50,23 @@ let }; path = mkOption { - type = types.str; + type = with types; either str path; description = "Path of the configuration file to include."; }; + + contents = mkOption { + type = types.attrs; + default = {}; + description = '' + Configuration to include. If empty then a path must be given. + ''; + }; }; - }; + + config.path = mkIf (config.contents != {}) ( + mkDefault (pkgs.writeText "contents" (generators.toINI {} config.contents)) + ); + }); in diff --git a/tests/modules/programs/git-expected.conf b/tests/modules/programs/git-expected.conf index 020fa8f0b..e6d23d116 100644 --- a/tests/modules/programs/git-expected.conf +++ b/tests/modules/programs/git-expected.conf @@ -29,3 +29,6 @@ path = ~/path/to/config.inc [includeIf "gitdir:~/src/dir"] path = ~/path/to/conditional.inc + +[includeIf "gitdir:~/src/dir"] +path = @git_include_path@ diff --git a/tests/modules/programs/git.nix b/tests/modules/programs/git.nix index be393d471..71573c384 100644 --- a/tests/modules/programs/git.nix +++ b/tests/modules/programs/git.nix @@ -1,7 +1,24 @@ -{ config, lib, ... }: +{ config, lib, pkgs, ... }: with lib; +let + + gitInclude = { + user = { + name = "John Doe"; + email = "user@example.org"; + }; + }; + + substituteExpected = path: pkgs.substituteAll { + src = path; + + git_include_path = pkgs.writeText "contents" (generators.toINI {} gitInclude); + }; + +in + { config = { programs.git = mkMerge [ @@ -23,6 +40,10 @@ with lib; path = "~/path/to/conditional.inc"; condition = "gitdir:~/src/dir"; } + { + condition = "gitdir:~/src/dir"; + contents = gitInclude; + } ]; signing = { gpgPath = "path-to-gpg"; @@ -43,7 +64,7 @@ with lib; nmt.script = '' assertFileExists home-files/.config/git/config - assertFileContent home-files/.config/git/config ${./git-expected.conf} + assertFileContent home-files/.config/git/config ${substituteExpected ./git-expected.conf} ''; }; }