diff options
author | Robert Helgesson <robert@rycee.net> | 2017-01-07 19:16:26 +0100 |
---|---|---|
committer | Robert Helgesson <robert@rycee.net> | 2017-01-14 13:15:24 +0100 |
commit | d7d02c3ce8f723b3cff03ea7502011883eef8fde (patch) | |
tree | f48d291967d59a91dd6590941745fb876c3a29bf /modules/programs/gnome-terminal.nix | |
parent | e4c63eb66aaa10e447f010b3d0f28e3a278ad30d (diff) |
Initial import
Diffstat (limited to 'modules/programs/gnome-terminal.nix')
-rw-r--r-- | modules/programs/gnome-terminal.nix | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/modules/programs/gnome-terminal.nix b/modules/programs/gnome-terminal.nix new file mode 100644 index 00000000000..90cf46adff1 --- /dev/null +++ b/modules/programs/gnome-terminal.nix @@ -0,0 +1,186 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.gnome-terminal; + + profileColorsSubModule = types.submodule ( + { ... }: { + options = { + foregroundColor = mkOption { + type = types.str; + description = "The foreground color."; + }; + + backgroundColor = mkOption { + type = types.str; + description = "The background color."; + }; + + boldColor = mkOption { + default = null; + type = types.nullOr types.str; + description = "The bold color, null to use same as foreground."; + }; + + palette = mkOption { + type = types.listOf types.str; + description = "The terminal palette."; + }; + }; + } + ); + + profileSubModule = types.submodule ( + { name, config, ... }: { + options = { + default = mkOption { + default = false; + type = types.bool; + description = "Whether this should be the default profile."; + }; + + visibleName = mkOption { + type = types.str; + description = "The profile name."; + }; + + colors = mkOption { + default = null; + type = types.nullOr profileColorsSubModule; + description = "The terminal colors, null to use system default."; + }; + + cursorShape = mkOption { + default = "block"; + type = types.enum [ "block" "ibeam" "underline" ]; + description = "The cursor shape."; + }; + + font = mkOption { + default = null; + type = types.nullOr types.str; + description = "The font name, null to use system default."; + }; + + scrollOnOutput = mkOption { + default = true; + type = types.bool; + description = "Whether to scroll when output is written."; + }; + + showScrollbar = mkOption { + default = true; + type = types.bool; + description = "Whether the scroll bar should be visible."; + }; + + scrollbackLines = mkOption { + default = 10000; + type = types.nullOr types.int; + description = + '' + The number of scrollback lines to keep, null for infinite. + ''; + }; + }; + } + ); + + toINI = (import ../lib/generators.nix).toINI { mkKeyValue = mkIniKeyValue; }; + + mkIniKeyValue = key: value: + let + tweakVal = v: + if isString v then "'${v}'" + else if isList v then "[" + concatStringsSep "," (map tweakVal v) + "]" + else if isBool v && v then "true" + else if isBool v && !v then "false" + else toString v; + in + "${key}=${tweakVal value}"; + + buildProfileSet = pcfg: + { + visible-name = pcfg.visibleName; + scrollbar-policy = if pcfg.showScrollbar then "always" else "never"; + scrollback-lines = pcfg.scrollbackLines; + cursor-shape = pcfg.cursorShape; + } + // ( + if (pcfg.font == null) + then { use-system-font = true; } + else { use-system-font = false; font = pcfg.font; } + ) // ( + if (pcfg.colors == null) + then { use-theme-colors = true; } + else ( + { + use-theme-colors = false; + foreground-color = pcfg.colors.foregroundColor; + background-color = pcfg.colors.backgroundColor; + palette = pcfg.colors.palette; + } + // ( + if (pcfg.colors.boldColor == null) + then { bold-color-same-as-fg = true; } + else { + bold-color-same-as-fg = false; + bold-color = pcfg.colors.boldColor; + } + ) + ) + ); + + buildIniSet = cfg: + { + "/" = { + default-show-menubar = cfg.showMenubar; + schema-version = 3; + }; + } + // + { + "profiles:" = { + default = head (attrNames (filterAttrs (n: v: v.default) cfg.profile)); + list = attrNames cfg.profile; #mapAttrsToList (n: v: n) cfg.profile; + }; + } + // + mapAttrs' (name: value: + nameValuePair ("profiles:/:${name}") (buildProfileSet value) + ) cfg.profile; + +in + +{ + options = { + programs.gnome-terminal = { + enable = mkEnableOption "Gnome Terminal"; + + showMenubar = mkOption { + default = true; + type = types.bool; + description = "Whether to show the menubar by default"; + }; + + profile = mkOption { + default = {}; + type = types.loaOf profileSubModule; + }; + }; + }; + + config = mkIf cfg.enable { + home.activation.gnome-terminal = + let + sf = pkgs.writeText "gnome-terminal.ini" (toINI (buildIniSet cfg)); + dconfPath = "/org/gnome/terminal/legacy/"; + in + '' + ${pkgs.gnome3.dconf}/bin/dconf load ${dconfPath} < ${sf} + ''; + }; +} |