1 { config, lib, pkgs, ... }:
5 cfg = config.programs.less;
7 configText = if (cfg.configFile != null) then (builtins.readFile cfg.configFile) else ''
9 ${builtins.concatStringsSep "\n"
10 (lib.mapAttrsToList (command: action: "${command} ${action}") cfg.commands)
12 ${lib.optionalString cfg.clearDefaultCommands "#stop"}
15 ${builtins.concatStringsSep "\n"
16 (lib.mapAttrsToList (command: action: "${command} ${action}") cfg.lineEditingKeys)
20 ${builtins.concatStringsSep "\n"
21 (lib.mapAttrsToList (variable: values: "${variable}=${values}") cfg.envVariables)
25 lessKey = pkgs.writeText "lessconfig" configText;
34 # note that environment.nix sets PAGER=less, and
35 # therefore also enables this module
36 enable = lib.mkEnableOption "less, a file pager";
38 package = lib.mkPackageOption pkgs "less" { };
40 configFile = lib.mkOption {
41 type = lib.types.nullOr lib.types.path;
43 example = lib.literalExpression ''"''${pkgs.my-configs}/lesskey"'';
45 Path to lesskey configuration file.
47 {option}`configFile` takes precedence over {option}`commands`,
48 {option}`clearDefaultCommands`, {option}`lineEditingKeys`, and
49 {option}`envVariables`.
53 commands = lib.mkOption {
54 type = lib.types.attrsOf lib.types.str;
60 description = "Defines new command keys.";
63 clearDefaultCommands = lib.mkOption {
64 type = lib.types.bool;
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 = lib.mkOption {
74 type = lib.types.attrsOf lib.types.str;
79 description = "Defines new line-editing keys.";
82 envVariables = lib.mkOption {
83 type = lib.types.attrsOf lib.types.str;
88 LESS = "--quit-if-one-screen";
90 description = "Defines environment variables.";
93 lessopen = lib.mkOption {
94 type = lib.types.nullOr lib.types.str;
95 default = "|${pkgs.lesspipe}/bin/lesspipe.sh %s";
96 defaultText = lib.literalExpression ''"|''${pkgs.lesspipe}/bin/lesspipe.sh %s"'';
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 = lib.mkOption {
103 type = lib.types.nullOr lib.types.str;
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 = lib.mkIf cfg.enable {
115 environment.systemPackages = [ cfg.package ];
117 environment.variables = {
118 LESSKEYIN_SYSTEM = builtins.toString lessKey;
119 } // lib.optionalAttrs (cfg.lessopen != null) {
120 LESSOPEN = cfg.lessopen;
121 } // lib.optionalAttrs (cfg.lessclose != null) {
122 LESSCLOSE = cfg.lessclose;
125 warnings = lib.optional (
126 cfg.clearDefaultCommands && (builtins.all (x: x != "quit") (builtins.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 lib.maintainers; [ johnazoidberg ];