summary refs log tree commit diff
path: root/nixos/modules/programs/less.nix
diff options
context:
space:
mode:
authorivanbrennan <ivan.brennan@gmail.com>2018-04-08 20:30:27 -0400
committerivanbrennan <ivan.brennan@gmail.com>2018-04-08 22:37:35 -0400
commit6e4096d792fb54651cb6f705b27efd8f64227fa7 (patch)
tree8021d400be2ef3f84445237e5138f4b50d6f765f /nixos/modules/programs/less.nix
parent2b6bae5699450e1cf764e02fd70f75822d3d8079 (diff)
downloadnixpkgs-6e4096d792fb54651cb6f705b27efd8f64227fa7.tar
nixpkgs-6e4096d792fb54651cb6f705b27efd8f64227fa7.tar.gz
nixpkgs-6e4096d792fb54651cb6f705b27efd8f64227fa7.tar.bz2
nixpkgs-6e4096d792fb54651cb6f705b27efd8f64227fa7.tar.lz
nixpkgs-6e4096d792fb54651cb6f705b27efd8f64227fa7.tar.xz
nixpkgs-6e4096d792fb54651cb6f705b27efd8f64227fa7.tar.zst
nixpkgs-6e4096d792fb54651cb6f705b27efd8f64227fa7.zip
nixos/less: add configFile option
Expose the path to a lesskey file as a module option. This makes it
possible to maintain a single lesskey file, used for both NixOS and
non-nix systems. An example of how this can be done follows.

1. Write a derivation that fetches lesskey from a known location:

  { stdenv, fetchgit }:
  stdenv.mkDerivation {
    name = "foo";
    src = fetchgit { .. };
    phases = [ "unpackPhase" "installPhase" ];
    installPhase = "mkdir -p $out && cp $src/lesskey $out/lesskey";
  }

2. Set programs.less.configFile to the corresponding path:

    programs.less = {
      enable = true;
      configFile = "${pkgs.foo}/lesskey";
    };
Diffstat (limited to 'nixos/modules/programs/less.nix')
-rw-r--r--nixos/modules/programs/less.nix17
1 files changed, 15 insertions, 2 deletions
diff --git a/nixos/modules/programs/less.nix b/nixos/modules/programs/less.nix
index c0283c9e686..d39103a5805 100644
--- a/nixos/modules/programs/less.nix
+++ b/nixos/modules/programs/less.nix
@@ -6,7 +6,7 @@ let
 
   cfg = config.programs.less;
 
-  configFile = ''
+  configText = if (cfg.configFile != null) then (builtins.readFile cfg.configFile) else ''
     #command
     ${concatStringsSep "\n"
       (mapAttrsToList (command: action: "${command} ${action}") cfg.commands)
@@ -25,7 +25,7 @@ let
   '';
 
   lessKey = pkgs.runCommand "lesskey"
-            { src = pkgs.writeText "lessconfig" configFile; }
+            { src = pkgs.writeText "lessconfig" configText; }
             "${pkgs.less}/bin/lesskey -o $out $src";
 
 in
@@ -37,6 +37,19 @@ in
 
       enable = mkEnableOption "less";
 
+      configFile = mkOption {
+        type = types.nullOr types.path;
+        default = null;
+        example = literalExample "$${pkgs.my-configs}/lesskey";
+        description = ''
+          Path to lesskey configuration file.
+
+          <option>configFile</option> takes precedence over <option>commands</option>,
+          <option>clearDefaultCommands</option>, <option>lineEditingKeys</option>, and
+          <option>envVariables</option>.
+        '';
+      };
+
       commands = mkOption {
         type = types.attrsOf types.str;
         default = {};