From 22f14d6909456808f02f181e62f52e44ecbf7865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Menou?= Date: Wed, 16 Oct 2024 15:40:29 +0200 Subject: [PATCH] Configuration options for git-bubbles The home-manager module now supports configuration options of the git-bubbles script. Fixes #45. --- README.md | 4 ++++ home-manager-module.nix | 33 ++++++++++++++++++++++++++++++--- tests/hm-module.nix | 3 +++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2eeffa3..ff52387 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,10 @@ The `your-home.nix` file might contain: { ptitfred.posix-toolbox.enable = true; + # Options for the git-bubbles script: + ptitfred.posix-toolbox.git-bubbles.remote-name = "some-remote-name"; + ptitfred.posix-toolbox.git-bubbles.pattern = "---"; + # You might have to enable git though: programs.git.enable = true; diff --git a/home-manager-module.nix b/home-manager-module.nix index 1d4aa0a..1d449ad 100644 --- a/home-manager-module.nix +++ b/home-manager-module.nix @@ -22,21 +22,48 @@ let cfg = config.ptitfred.posix-toolbox; lib.strings.optionalString config.programs.git.enable "source ${posix-toolbox.git-ps1}/share/posix-toolbox/git-ps1"; - initExtra = + bashInitExtra = '' ${gitBashInitExtra} source ${posix-toolbox.ls-colors}/share/ls-colors/bash.sh ''; + + gitExtraConfig = { + bubbles = lib.attrsets.filterAttrs (_: value: ! (isNull value)) cfg.git-bubbles; + }; + + mkOptionalStr = description: + lib.mkOption { + inherit description; + type = lib.types.nullOr lib.types.str; + default = null; + }; in { options = { - ptitfred.posix-toolbox.enable = lib.mkEnableOption "posix-toolbox"; + ptitfred.posix-toolbox = { + enable = lib.mkEnableOption "posix-toolbox"; + + git-bubbles = lib.mkOption { + description = "options for git-bubbles"; + default = {}; + type = (lib.types.submodule { + options = { + remote-name = mkOptionalStr "remote-name"; + pattern = mkOptionalStr "pattern"; + }; + }); + }; + }; }; config = { home.packages = lib.mkIf cfg.enable packages; programs.bash.initExtra = - lib.mkIf (cfg.enable && config.programs.bash.enable) initExtra; + lib.mkIf (cfg.enable && config.programs.bash.enable) bashInitExtra; + + programs.git.extraConfig = + lib.mkIf (cfg.enable && config.programs.git.enable) gitExtraConfig; }; } diff --git a/tests/hm-module.nix b/tests/hm-module.nix index 72703e7..f7fe1ad 100644 --- a/tests/hm-module.nix +++ b/tests/hm-module.nix @@ -14,4 +14,7 @@ # This is how you enable posix-toolbox features (depends on bash and git being active): ptitfred.posix-toolbox.enable = true; + + # Example configuration for git-bubbles: + ptitfred.posix-toolbox.git-bubbles.remote-name = "mine"; }