fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
1.7 KiB84 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.jq;
8
9  colorType = mkOption {
10    type = types.str;
11    description = "ANSI color definition";
12    example = "1;31";
13    visible = false;
14  };
15
16  colorsType = types.submodule {
17    options = {
18      null = colorType;
19      false = colorType;
20      true = colorType;
21      numbers = colorType;
22      strings = colorType;
23      arrays = colorType;
24      objects = colorType;
25    };
26  };
27
28in {
29  options = {
30    programs.jq = {
31      enable = mkEnableOption "the jq command-line JSON processor";
32
33      package = mkOption {
34        type = types.package;
35        default = pkgs.jq;
36        defaultText = literalExpression "pkgs.jq";
37        description = "jq package to use.";
38      };
39
40      colors = mkOption {
41        description = ''
42          The colors used in colored JSON output.
43
44          See the [Colors section](https://jqlang.github.io/jq/manual/#Colors)
45          of the jq manual.
46        '';
47
48        example = literalExpression ''
49          {
50            null    = "1;30";
51            false   = "0;31";
52            true    = "0;32";
53            numbers = "0;36";
54            strings = "0;33";
55            arrays  = "1;35";
56            objects = "1;37";
57          }
58        '';
59
60        default = {
61          null = "1;30";
62          false = "0;37";
63          true = "0;37";
64          numbers = "0;37";
65          strings = "0;32";
66          arrays = "1;37";
67          objects = "1;37";
68        };
69
70        type = colorsType;
71      };
72    };
73  };
74
75  config = mkIf cfg.enable {
76    home.packages = [ cfg.package ];
77
78    home.sessionVariables = let c = cfg.colors;
79    in {
80      JQ_COLORS =
81        "${c.null}:${c.false}:${c.true}:${c.numbers}:${c.strings}:${c.arrays}:${c.objects}";
82    };
83  };
84}