From 6e4096d792fb54651cb6f705b27efd8f64227fa7 Mon Sep 17 00:00:00 2001 From: ivanbrennan Date: Sun, 8 Apr 2018 20:30:27 -0400 Subject: [PATCH] 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"; }; --- nixos/modules/programs/less.nix | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/nixos/modules/programs/less.nix b/nixos/modules/programs/less.nix index c0283c9e6862..d39103a58057 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. + + takes precedence over , + , , and + . + ''; + }; + commands = mkOption { type = types.attrsOf types.str; default = {};