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";
};

+15 -2
+15 -2
nixos/modules/programs/less.nix
··· 6 6 7 7 cfg = config.programs.less; 8 8 9 - configFile = '' 9 + configText = if (cfg.configFile != null) then (builtins.readFile cfg.configFile) else '' 10 10 #command 11 11 ${concatStringsSep "\n" 12 12 (mapAttrsToList (command: action: "${command} ${action}") cfg.commands) ··· 25 25 ''; 26 26 27 27 lessKey = pkgs.runCommand "lesskey" 28 - { src = pkgs.writeText "lessconfig" configFile; } 28 + { src = pkgs.writeText "lessconfig" configText; } 29 29 "${pkgs.less}/bin/lesskey -o $out $src"; 30 30 31 31 in ··· 36 36 programs.less = { 37 37 38 38 enable = mkEnableOption "less"; 39 + 40 + configFile = mkOption { 41 + type = types.nullOr types.path; 42 + default = null; 43 + example = literalExample "$${pkgs.my-configs}/lesskey"; 44 + description = '' 45 + Path to lesskey configuration file. 46 + 47 + <option>configFile</option> takes precedence over <option>commands</option>, 48 + <option>clearDefaultCommands</option>, <option>lineEditingKeys</option>, and 49 + <option>envVariables</option>. 50 + ''; 51 + }; 39 52 40 53 commands = mkOption { 41 54 type = types.attrsOf types.str;