diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 4af6d6aa5..fe48aa1f0 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -929,6 +929,13 @@ in A new module is available: 'programs.opam'. ''; } + + { + time = "2019-01-18T00:21:56+00:00"; + message = '' + A new module is available: 'programs.matplotlib'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 45cb8d518..1ca4cee50 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -60,6 +60,7 @@ let (loadModule ./programs/jq.nix { }) (loadModule ./programs/lesspipe.nix { }) (loadModule ./programs/man.nix { }) + (loadModule ./programs/matplotlib.nix { }) (loadModule ./programs/mbsync.nix { }) (loadModule ./programs/mercurial.nix { }) (loadModule ./programs/msmtp.nix { }) diff --git a/modules/programs/matplotlib.nix b/modules/programs/matplotlib.nix new file mode 100644 index 000000000..48ff6e60d --- /dev/null +++ b/modules/programs/matplotlib.nix @@ -0,0 +1,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 matplotlibrc 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 + matplotlibrc file. + ''; + }; + }; + + config = mkIf cfg.enable { + xdg.configFile."matplotlib/matplotlibrc".text = + concatStringsSep "\n" ([] + ++ mapAttrsToList (formatLine "") cfg.config + ++ optional (cfg.extraConfig != "") cfg.extraConfig + ) + "\n"; + }; +}