fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
1.4 KiB59 linesraw
1{ config, lib, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.matplotlib;
8
9  formatLine = o: n: v:
10    let
11      formatValue = v:
12        if isBool v then (if v then "True" else "False") else toString v;
13    in if isAttrs v then
14      concatStringsSep "\n" (mapAttrsToList (formatLine "${o}${n}.") v)
15    else
16      (if v == "" then "" else "${o}${n}: ${formatValue v}");
17
18in {
19  meta.maintainers = [ maintainers.rprospero ];
20
21  options.programs.matplotlib = {
22    enable = mkEnableOption "matplotlib, a plotting library for python";
23
24    config = mkOption {
25      default = { };
26      type = types.attrsOf types.anything;
27      description = ''
28        Add terms to the {file}`matplotlibrc` file to
29        control the default matplotlib behavior.
30      '';
31      example = literalExpression ''
32        {
33          backend = "Qt5Agg";
34          axes = {
35            grid = true;
36            facecolor = "black";
37            edgecolor = "FF9900";
38          };
39          grid.color = "FF9900";
40        }
41      '';
42    };
43
44    extraConfig = mkOption {
45      type = types.lines;
46      default = "";
47      description = ''
48        Additional commands for matplotlib that will be added to the
49        {file}`matplotlibrc` file.
50      '';
51    };
52  };
53
54  config = mkIf cfg.enable {
55    xdg.configFile."matplotlib/matplotlibrc".text = concatStringsSep "\n" ([ ]
56      ++ mapAttrsToList (formatLine "") cfg.config
57      ++ optional (cfg.extraConfig != "") cfg.extraConfig) + "\n";
58  };
59}