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

Changed files
+15 -2
nixos
modules
programs
+15 -2
nixos/modules/programs/less.nix
···
cfg = config.programs.less;
-
configFile = ''
#command
${concatStringsSep "\n"
(mapAttrsToList (command: action: "${command} ${action}") cfg.commands)
···
'';
lessKey = pkgs.runCommand "lesskey"
-
{ src = pkgs.writeText "lessconfig" configFile; }
"${pkgs.less}/bin/lesskey -o $out $src";
in
···
programs.less = {
enable = mkEnableOption "less";
commands = mkOption {
type = types.attrsOf types.str;
···
cfg = config.programs.less;
+
configText = if (cfg.configFile != null) then (builtins.readFile cfg.configFile) else ''
#command
${concatStringsSep "\n"
(mapAttrsToList (command: action: "${command} ${action}") cfg.commands)
···
'';
lessKey = pkgs.runCommand "lesskey"
+
{ src = pkgs.writeText "lessconfig" configText; }
"${pkgs.less}/bin/lesskey -o $out $src";
in
···
programs.less = {
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;