fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

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