1 { config, lib, pkgs, ... }:
7 cfg = config.programs.less;
9 configText = if (cfg.configFile != null) then (builtins.readFile cfg.configFile) else ''
11 ${concatStringsSep "\n"
12 (mapAttrsToList (command: action: "${command} ${action}") cfg.commands)
14 ${if cfg.clearDefaultCommands then "#stop" else ""}
17 ${concatStringsSep "\n"
18 (mapAttrsToList (command: action: "${command} ${action}") cfg.lineEditingKeys)
22 ${concatStringsSep "\n"
23 (mapAttrsToList (variable: values: "${variable}=${values}") cfg.envVariables)
27 lessKey = pkgs.writeText "lessconfig" configText;
36 # note that environment.nix sets PAGER=less, and
37 # therefore also enables this module
38 enable = mkEnableOption (lib.mdDoc "less");
40 configFile = mkOption {
41 type = types.nullOr types.path;
43 example = literalExpression ''"''${pkgs.my-configs}/lesskey"'';
44 description = lib.mdDoc ''
45 Path to lesskey configuration file.
47 {option}`configFile` takes precedence over {option}`commands`,
48 {option}`clearDefaultCommands`, {option}`lineEditingKeys`, and
49 {option}`envVariables`.
54 type = types.attrsOf types.str;
60 description = lib.mdDoc "Defines new command keys.";
63 clearDefaultCommands = mkOption {
66 description = lib.mdDoc ''
67 Clear all default commands.
68 You should remember to set the quit key.
69 Otherwise you will not be able to leave less without killing it.
73 lineEditingKeys = mkOption {
74 type = types.attrsOf types.str;
79 description = lib.mdDoc "Defines new line-editing keys.";
82 envVariables = mkOption {
83 type = types.attrsOf types.str;
88 LESS = "--quit-if-one-screen";
90 description = lib.mdDoc "Defines environment variables.";
94 type = types.nullOr types.str;
95 default = "|${pkgs.lesspipe}/bin/lesspipe.sh %s";
96 defaultText = literalExpression ''"|''${pkgs.lesspipe}/bin/lesspipe.sh %s"'';
97 description = lib.mdDoc ''
98 Before less opens a file, it first gives your input preprocessor a chance to modify the way the contents of the file are displayed.
102 lessclose = mkOption {
103 type = types.nullOr types.str;
105 description = lib.mdDoc ''
106 When less closes a file opened in such a way, it will call another program, called the input postprocessor,
107 which may perform any desired clean-up action (such as deleting the replacement file created by LESSOPEN).
113 config = mkIf cfg.enable {
115 environment.systemPackages = [ pkgs.less ];
117 environment.variables = {
118 LESSKEYIN_SYSTEM = toString lessKey;
119 } // optionalAttrs (cfg.lessopen != null) {
120 LESSOPEN = cfg.lessopen;
121 } // optionalAttrs (cfg.lessclose != null) {
122 LESSCLOSE = cfg.lessclose;
125 warnings = optional (
126 cfg.clearDefaultCommands && (all (x: x != "quit") (attrValues cfg.commands))
128 config.programs.less.clearDefaultCommands clears all default commands of less but there is no alternative binding for exiting.
129 Consider adding a binding for 'quit'.
133 meta.maintainers = with maintainers; [ johnazoidberg ];