From c2cff13f15f17a2bb9e387009564f166c2ad7a6f Mon Sep 17 00:00:00 2001 From: Olli Helenius Date: Sun, 9 Dec 2018 15:36:21 +0200 Subject: [PATCH] jq: add module (cherry picked from commit dc72aa230596c5e10f4bfaf519392999dfd343cd) --- modules/misc/news.nix | 7 ++++ modules/modules.nix | 1 + modules/programs/jq.nix | 76 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 modules/programs/jq.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 441e01f4..c69a4c56 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -888,6 +888,13 @@ in to your configuration. ''; } + + { + time = "2018-12-12T21:02:05+00:00"; + message = '' + A new module is available: 'programs.jq'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 7a8dd453..ec5f0b2d 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -47,6 +47,7 @@ let ./programs/home-manager.nix ./programs/htop.nix ./programs/info.nix + ./programs/jq.nix ./programs/lesspipe.nix ./programs/man.nix ./programs/mbsync.nix diff --git a/modules/programs/jq.nix b/modules/programs/jq.nix new file mode 100644 index 00000000..56c3adf0 --- /dev/null +++ b/modules/programs/jq.nix @@ -0,0 +1,76 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.jq; + + colorType = mkOption { + type = types.str; + description = "ANSI color definition"; + example = "1;31"; + visible = false; + }; + + colorsType = types.submodule { + options = { + null = colorType; + false = colorType; + true = colorType; + numbers = colorType; + strings = colorType; + arrays = colorType; + objects = colorType; + }; + }; + +in + +{ + options = { + programs.jq = { + enable = mkEnableOption "the jq command-line JSON processor"; + + colors = mkOption { + description = '' + The colors used in colored JSON output. + + See . + ''; + + example = literalExample '' + { + null = "1;30"; + false = "0;31"; + true = "0;32"; + numbers = "0;36"; + strings = "0;33"; + arrays = "1;35"; + objects = "1;37"; + } + ''; + + default = { + null = "1;30"; + false = "0;39"; + true = "0;39"; + numbers = "0;39"; + strings = "0;32"; + arrays = "1;39"; + objects = "1;39"; + }; + + type = colorsType; + }; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ pkgs.jq ]; + + home.sessionVariables = let c = cfg.colors; in { + JQ_COLORS = "${c.null}:${c.false}:${c.true}:${c.numbers}:${c.strings}:${c.arrays}:${c.objects}"; + }; + }; +}