aboutsummaryrefslogtreecommitdiff
path: root/home-manager/modules/programs/matplotlib.nix
blob: 48ff6e60d681b84c9bed2a30ab47d6ff48c90a72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{ config, lib, ... }:

with lib;

let

  cfg = config.programs.matplotlib;

  formatLine = o: n: v:
    let
      formatValue = v:
        if isBool v then (if v then "True" else "False")
        else toString v;
    in
      if isAttrs v
      then concatStringsSep "\n" (mapAttrsToList (formatLine "${o}${n}.") v)
      else (if v == "" then "" else "${o}${n}: ${formatValue v}");

in

{
  meta.maintainers = [ maintainers.rprospero ];

  options.programs.matplotlib = {
    enable = mkEnableOption "matplotlib, a plotting library for python";

    config = mkOption {
      default = { };
      type = types.attrs;
      description = ''
        Add terms to the <filename>matplotlibrc</filename> file to
        control the default matplotlib behavior.
      '';
      example = literalExample  ''
        {
          backend = "Qt5Agg";
          axes = {
            grid = true;
            facecolor = "black";
            edgecolor = "FF9900";
          };
          grid.color = "FF9900";
        }
      '';
    };

    extraConfig = mkOption {
      type = types.lines;
      default = "";
      description = ''
        Additional commands for matplotlib that will be added to the
        <filename>matplotlibrc</filename> file.
      '';
    };
  };

  config = mkIf cfg.enable {
    xdg.configFile."matplotlib/matplotlibrc".text =
      concatStringsSep "\n" ([]
        ++ mapAttrsToList (formatLine "") cfg.config
        ++ optional (cfg.extraConfig != "") cfg.extraConfig
      ) + "\n";
  };
}