summary refs log tree commit diff
path: root/nixos/modules/programs/less.nix
diff options
context:
space:
mode:
authorDaniel Schaefer <git@danielschaefer.me>2018-01-29 22:08:32 +0700
committerDaniel Schaefer <git@danielschaefer.me>2018-01-29 22:08:32 +0700
commit288898d6f1dc532e1dfb8785a591a2d8ad55320b (patch)
tree6c07df03b5c2c170f73ec2da3a9f14dc4c12b08a /nixos/modules/programs/less.nix
parent192c2330d08ff2dda2ff0a7986fec9cb1e60d27b (diff)
downloadnixpkgs-288898d6f1dc532e1dfb8785a591a2d8ad55320b.tar
nixpkgs-288898d6f1dc532e1dfb8785a591a2d8ad55320b.tar.gz
nixpkgs-288898d6f1dc532e1dfb8785a591a2d8ad55320b.tar.bz2
nixpkgs-288898d6f1dc532e1dfb8785a591a2d8ad55320b.tar.lz
nixpkgs-288898d6f1dc532e1dfb8785a591a2d8ad55320b.tar.xz
nixpkgs-288898d6f1dc532e1dfb8785a591a2d8ad55320b.tar.zst
nixpkgs-288898d6f1dc532e1dfb8785a591a2d8ad55320b.zip
nixos/less: use lesspipe package for preprocessing
Rather than a custom script the less config now uses the lesspipe
package config by default.
Diffstat (limited to 'nixos/modules/programs/less.nix')
-rw-r--r--nixos/modules/programs/less.nix43
1 files changed, 19 insertions, 24 deletions
diff --git a/nixos/modules/programs/less.nix b/nixos/modules/programs/less.nix
index a7f2290764a..c0283c9e686 100644
--- a/nixos/modules/programs/less.nix
+++ b/nixos/modules/programs/less.nix
@@ -28,24 +28,6 @@ let
             { src = pkgs.writeText "lessconfig" configFile; }
             "${pkgs.less}/bin/lesskey -o $out $src";
 
-  lessPipe = pkgs.writeScriptBin "lesspipe.sh" ''
-    #! /bin/sh
-    case "$1" in
-    *.gz)
-        ${pkgs.gzip}/bin/gunzip --stdout "$1" 2>/dev/null
-        ;;
-    *.xz)
-        ${pkgs.xz}/bin/unxz --stdout "$1" 2>/dev/null
-        ;;
-    *.bz2)
-        ${pkgs.bzip2}/bin/bunzip2 --stdout "$1" 2>/dev/null
-        ;;
-    *)  exit 1
-        ;;
-    esac
-    exit $?
-  '';
-
 in
 
 {
@@ -93,11 +75,19 @@ in
         description = "Defines environment variables.";
       };
 
-      autoExtract = mkOption {
-        type = types.bool;
-        default = true;
+      lessopen = mkOption {
+        type = types.nullOr types.str;
+        default = "|${pkgs.lesspipe}/bin/lesspipe.sh %s";
+        description = ''
+          Before less opens a file, it first gives your input preprocessor a chance to modify the way the contents of the file are displayed.
+        '';
+      };
+
+      lessclose = mkOption {
+        type = types.nullOr types.str;
+        default = null;
         description = ''
-          When enabled less automatically extracts .gz .xz .bz2 files before reading them.
+          When less closes a file opened in such a way, it will call another program, called the input postprocessor, which may  perform  any  desired  clean-up  action (such  as deleting the replacement file created by LESSOPEN).
         '';
       };
     };
@@ -107,8 +97,13 @@ in
 
     environment.systemPackages = [ pkgs.less ];
 
-    environment.variables."LESSKEY_SYSTEM" = toString lessKey;
-    environment.variables."LESSOPEN" = "|${lessPipe}/bin/lesspipe.sh %s";
+    environment.variables = {
+      "LESSKEY_SYSTEM" = toString lessKey;
+    } // optionalAttrs (cfg.lessopen != null) {
+      "LESSOPEN" = cfg.lessopen;
+    } // optionalAttrs (cfg.lessclose != null) {
+      "LESSCLOSE" = cfg.lessclose;
+    };
 
     warnings = optional (
       cfg.clearDefaultCommands && (all (x: x != "quit") (attrValues cfg.commands))