From a2a0a58f7c6c3d6f1174524333c078052916841f Mon Sep 17 00:00:00 2001 From: Matt McHenry Date: Tue, 5 Oct 2021 05:13:48 -0400 Subject: [PATCH] less: improve default settings (#139988) * less: enable by default and set LESS=-R via lesskey * since we set PAGER=less, programs.less.enable should default to true. * some programs, notably git, set a custom LESS environment if none is present. using the lesskey mechanism to set LESS=-R lets such programs continue to run less as they see fit. This reverts commit 0e7b4e60a846af1d4487ebe1218f8e07fffaa89b. * less: remove use of deprecated lesskey binary format * less: enable in environment.nix rather than less.nix per discussion in #139988 --- nixos/modules/programs/environment.nix | 6 +++++- nixos/modules/programs/less.nix | 12 +++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/nixos/modules/programs/environment.nix b/nixos/modules/programs/environment.nix index 39010323f61e..d552c751afd7 100644 --- a/nixos/modules/programs/environment.nix +++ b/nixos/modules/programs/environment.nix @@ -18,12 +18,16 @@ in environment.variables = { NIXPKGS_CONFIG = "/etc/nix/nixpkgs-config.nix"; + # note: many programs exec() this directly, so default options for less must not + # be specified here; do so in the default value of programs.less.envVariables instead PAGER = mkDefault "less"; - LESS = mkDefault "-R"; EDITOR = mkDefault "nano"; XDG_CONFIG_DIRS = [ "/etc/xdg" ]; # needs to be before profile-relative paths to allow changes through environment.etc }; + # since we set PAGER to this above, make sure it's installed + programs.less.enable = true; + environment.profiles = mkAfter [ "/nix/var/nix/profiles/default" "/run/current-system/sw" diff --git a/nixos/modules/programs/less.nix b/nixos/modules/programs/less.nix index c0188788ec74..794146b19faf 100644 --- a/nixos/modules/programs/less.nix +++ b/nixos/modules/programs/less.nix @@ -24,9 +24,7 @@ let } ''; - lessKey = pkgs.runCommand "lesskey" - { src = pkgs.writeText "lessconfig" configText; preferLocalBuild = true; } - "${pkgs.less}/bin/lesskey -o $out $src"; + lessKey = pkgs.writeText "lessconfig" configText; in @@ -35,6 +33,8 @@ in programs.less = { + # note that environment.nix sets PAGER=less, and + # therefore also enables this module enable = mkEnableOption "less"; configFile = mkOption { @@ -81,7 +81,9 @@ in envVariables = mkOption { type = types.attrsOf types.str; - default = {}; + default = { + LESS = "-R"; + }; example = { LESS = "--quit-if-one-screen"; }; @@ -112,7 +114,7 @@ in environment.systemPackages = [ pkgs.less ]; environment.variables = { - LESSKEY_SYSTEM = toString lessKey; + LESSKEYIN_SYSTEM = toString lessKey; } // optionalAttrs (cfg.lessopen != null) { LESSOPEN = cfg.lessopen; } // optionalAttrs (cfg.lessclose != null) {