From 67393957c27b4e4c6c48a60108a201413ced7800 Mon Sep 17 00:00:00 2001 From: Benedikt Rips Date: Mon, 4 Aug 2025 10:39:44 +0200 Subject: [PATCH] less: configure LESS options --- modules/programs/less.nix | 25 +++++++++++++++++ tests/modules/programs/less/custom-config.nix | 1 + .../less/custom-options-and-config.nix | 27 +++++++++++++++++++ .../modules/programs/less/custom-options.nix | 18 +++++++++++++ tests/modules/programs/less/default.nix | 2 ++ 5 files changed, 73 insertions(+) create mode 100644 tests/modules/programs/less/custom-options-and-config.nix create mode 100644 tests/modules/programs/less/custom-options.nix diff --git a/modules/programs/less.nix b/modules/programs/less.nix index c8f8847f2..1a8c5fb77 100644 --- a/modules/programs/less.nix +++ b/modules/programs/less.nix @@ -24,6 +24,7 @@ in type = lib.types.lines; default = ""; example = '' + #command s back-line t forw-line ''; @@ -32,6 +33,23 @@ in {file}`$XDG_CONFIG_HOME/lesskey`. ''; }; + + options = lib.mkOption { + type = + with lib.types; + attrsOf (oneOf [ + bool + int + str + ]); + default = { }; + description = "GNU-style options to be set via {env}`$LESS`."; + example = { + RAW-CONTROL-CHARS = true; + quiet = true; + wheel-lines = 3; + }; + }; }; }; @@ -39,5 +57,12 @@ in home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; xdg.configFile."lesskey" = lib.mkIf (cfg.config != "") { text = cfg.config; }; + + programs.less.config = lib.mkIf (cfg.options != { }) ( + lib.mkBefore '' + #env + LESS = ${lib.cli.toGNUCommandLineShell { } cfg.options} + '' + ); }; } diff --git a/tests/modules/programs/less/custom-config.nix b/tests/modules/programs/less/custom-config.nix index ee6755c9b..f1c832db1 100644 --- a/tests/modules/programs/less/custom-config.nix +++ b/tests/modules/programs/less/custom-config.nix @@ -1,5 +1,6 @@ let config = '' + #command s back-line t forw-line ''; diff --git a/tests/modules/programs/less/custom-options-and-config.nix b/tests/modules/programs/less/custom-options-and-config.nix new file mode 100644 index 000000000..421a55cd2 --- /dev/null +++ b/tests/modules/programs/less/custom-options-and-config.nix @@ -0,0 +1,27 @@ +let + config = '' + #command + s back-line + t forw-line + ''; +in +{ + programs.less = { + enable = true; + inherit config; + options = { + RAW-CONTROL-CHARS = true; + quiet = true; + wheel-lines = 3; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/lesskey + assertFileContent home-files/.config/lesskey ${builtins.toFile "less.expected" '' + #env + LESS = --RAW-CONTROL-CHARS --quiet --wheel-lines 3 + + ${config}''} + ''; +} diff --git a/tests/modules/programs/less/custom-options.nix b/tests/modules/programs/less/custom-options.nix new file mode 100644 index 000000000..2e97f7d68 --- /dev/null +++ b/tests/modules/programs/less/custom-options.nix @@ -0,0 +1,18 @@ +{ + programs.less = { + enable = true; + options = { + RAW-CONTROL-CHARS = true; + quiet = true; + wheel-lines = 3; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/lesskey + assertFileContent home-files/.config/lesskey ${builtins.toFile "lesskey.expected" '' + #env + LESS = --RAW-CONTROL-CHARS --quiet --wheel-lines 3 + ''} + ''; +} diff --git a/tests/modules/programs/less/default.nix b/tests/modules/programs/less/default.nix index c109210d9..675c1a6c2 100644 --- a/tests/modules/programs/less/default.nix +++ b/tests/modules/programs/less/default.nix @@ -1,4 +1,6 @@ { less-custom-config = ./custom-config.nix; + less-custom-options = ./custom-options.nix; + less-custom-options-and-config = ./custom-options-and-config.nix; less-no-config = ./no-config.nix; }