2018-12-09 14:36:21 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.jq;
|
|
|
|
|
|
|
|
colorType = mkOption {
|
|
|
|
type = types.str;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "ANSI color definition";
|
2018-12-09 14:36:21 +01:00
|
|
|
example = "1;31";
|
|
|
|
visible = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
colorsType = types.submodule {
|
|
|
|
options = {
|
2020-02-02 00:39:17 +01:00
|
|
|
null = colorType;
|
|
|
|
false = colorType;
|
|
|
|
true = colorType;
|
2018-12-09 14:36:21 +01:00
|
|
|
numbers = colorType;
|
|
|
|
strings = colorType;
|
2020-02-02 00:39:17 +01:00
|
|
|
arrays = colorType;
|
2018-12-09 14:36:21 +01:00
|
|
|
objects = colorType;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2018-12-09 14:36:21 +01:00
|
|
|
options = {
|
|
|
|
programs.jq = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "the jq command-line JSON processor";
|
2018-12-09 14:36:21 +01:00
|
|
|
|
2019-03-21 23:55:28 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.jq;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "pkgs.jq";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "jq package to use.";
|
2019-03-21 23:55:28 +01:00
|
|
|
};
|
|
|
|
|
2018-12-09 14:36:21 +01:00
|
|
|
colors = mkOption {
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 00:35:51 +02:00
|
|
|
The colors used in colored JSON output.
|
2018-12-09 14:36:21 +01:00
|
|
|
|
2023-07-01 00:35:51 +02:00
|
|
|
See the [Colors section](https://jqlang.github.io/jq/manual/#Colors)
|
|
|
|
of the jq manual.
|
2018-12-09 14:36:21 +01:00
|
|
|
'';
|
|
|
|
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2018-12-09 14:36:21 +01:00
|
|
|
{
|
|
|
|
null = "1;30";
|
|
|
|
false = "0;31";
|
|
|
|
true = "0;32";
|
|
|
|
numbers = "0;36";
|
|
|
|
strings = "0;33";
|
|
|
|
arrays = "1;35";
|
|
|
|
objects = "1;37";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
default = {
|
2020-02-02 00:39:17 +01:00
|
|
|
null = "1;30";
|
2021-03-18 23:19:42 +01:00
|
|
|
false = "0;37";
|
|
|
|
true = "0;37";
|
|
|
|
numbers = "0;37";
|
2018-12-09 14:36:21 +01:00
|
|
|
strings = "0;32";
|
2021-03-18 23:19:42 +01:00
|
|
|
arrays = "1;37";
|
|
|
|
objects = "1;37";
|
2018-12-09 14:36:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
type = colorsType;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2019-03-21 23:55:28 +01:00
|
|
|
home.packages = [ cfg.package ];
|
2018-12-09 14:36:21 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
home.sessionVariables = let c = cfg.colors;
|
|
|
|
in {
|
|
|
|
JQ_COLORS =
|
|
|
|
"${c.null}:${c.false}:${c.true}:${c.numbers}:${c.strings}:${c.arrays}:${c.objects}";
|
2018-12-09 14:36:21 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|