fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . pet ; 8 9format = pkgs . formats . toml { }; 10 11snippetType = types . submodule { 12options = { 13description = mkOption { 14type = types . str ; 15default = "" ; 16example = "Count the number of commits in the current branch" ; 17description = '' 18Description of the snippet. 19'' ; 20}; 21 22command = mkOption { 23type = types . str ; 24default = "" ; 25example = "git rev-list --count HEAD" ; 26description = '' 27The command. 28'' ; 29}; 30 31output = mkOption { 32type = types . str ; 33default = "" ; 34example = "473" ; 35description = '' 36Example output of the command. 37'' ; 38}; 39 40tag = mkOption { 41type = types . listOf types . str ; 42default = [ ]; 43example = literalExpression ''["git" "nixpkgs"]'' ; 44description = '' 45List of tags attached to the command. 46'' ; 47}; 48}; 49}; 50 51in { 52options . programs . pet = { 53enable = mkEnableOption "pet" ; 54 55settings = mkOption { 56type = format . type ; 57default = { }; 58description = '' 59Settings written to {file}`config.toml`. See the pet 60documentation for details. 61'' ; 62}; 63 64selectcmdPackage = mkOption { 65type = types . package ; 66default = pkgs . fzf ; 67defaultText = literalExpression "pkgs.fzf" ; 68description = '' 69The package needed for the {var}`settings.selectcmd`. 70'' ; 71}; 72 73snippets = mkOption { 74type = types . listOf snippetType ; 75default = [ ]; 76description = '' 77The snippets. 78'' ; 79}; 80}; 81 82config = mkIf cfg . enable { 83programs . pet . settings = let 84defaultGeneral = { 85selectcmd = mkDefault "fzf" ; 86snippetfile = config . xdg . configHome + "/pet/snippet.toml" ; 87}; 88in if versionAtLeast config . home . stateVersion "21.11" then { 89General = defaultGeneral ; 90} else 91defaultGeneral ; 92 93home . packages = [ pkgs . pet cfg . selectcmdPackage ]; 94 95xdg . configFile = { 96"pet/config.toml" . source = format . generate "config.toml" 97( if versionAtLeast config . home . stateVersion "21.11" then 98cfg . settings 99else { 100General = cfg . settings ; 101}); 102"pet/snippet.toml" = mkIf ( cfg . snippets != [ ]) { 103source = format . generate "snippet.toml" { snippets = cfg . snippets ; }; 104}; 105}; 106}; 107}