fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
2.0 KiB84 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.readline;
8
9  mkSetVariableStr = n: v:
10    let
11      mkValueStr = v:
12        if v == true then
13          "on"
14        else if v == false then
15          "off"
16        else if isInt v then
17          toString v
18        else if isString v then
19          v
20        else
21          abort ("values ${toPretty v} is of unsupported type");
22    in "set ${n} ${mkValueStr v}";
23
24  mkBindingStr = k: v:
25    let
26      isKeynameNotKeyseq = k:
27        builtins.elem (builtins.head (lib.splitString "-" (toLower k))) [
28          "control"
29          "meta"
30        ];
31    in if isKeynameNotKeyseq k then "${k}: ${v}" else ''"${k}": ${v}'';
32
33in {
34  options.programs.readline = {
35    enable = mkEnableOption "readline";
36
37    bindings = mkOption {
38      default = { };
39      type = types.attrsOf types.str;
40      example = literalExpression ''
41        { "\\C-h" = "backward-kill-word"; }
42      '';
43      description = "Readline bindings.";
44    };
45
46    variables = mkOption {
47      type = with types; attrsOf (either str (either int bool));
48      default = { };
49      example = { expand-tilde = true; };
50      description = ''
51        Readline customization variable assignments.
52      '';
53    };
54
55    includeSystemConfig = mkOption {
56      type = types.bool;
57      default = true;
58      description = "Whether to include the system-wide configuration.";
59    };
60
61    extraConfig = mkOption {
62      type = types.lines;
63      default = "";
64      description = ''
65        Configuration lines appended unchanged to the end of the
66        {file}`~/.inputrc` file.
67      '';
68    };
69  };
70
71  config = mkIf cfg.enable {
72    home.file.".inputrc".text = let
73      configStr = concatStringsSep "\n"
74        (optional cfg.includeSystemConfig "$include /etc/inputrc"
75          ++ mapAttrsToList mkSetVariableStr cfg.variables
76          ++ mapAttrsToList mkBindingStr cfg.bindings);
77    in ''
78      # Generated by Home Manager.
79
80      ${configStr}
81      ${cfg.extraConfig}
82    '';
83  };
84}