about summary refs log tree commit diff
path: root/home/modules/programs/zshell/default.nix
blob: 514002aa499ff1a4dc53578d18afda994ef1f4f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{ config, lib, ... }:
let
  cfg = config.programs.zshell;
  aliasesStr = lib.concatStringsSep "\n"
    (lib.mapAttrsToList (k: v: "alias ${k}=${lib.escapeShellArg v}")
      cfg.aliases);
  sourcesStr =
    lib.concatStringsSep "\n" (builtins.map (s: ". ${s}") cfg.sources);
in
{
  options.programs.zshell = {
    aliases = lib.mkOption {
      default = { };
      example = {
        ll = "ls -l";
        ".." = "cd ..";
      };
      description = ''
        An attribute set that maps aliases (the top level attribute names in
        this option) to command strings or directly to build outputs.
      '';
      type = lib.types.attrsOf lib.types.str;
    };
    sources = lib.mkOption {
      default = [ ];
      type = lib.types.listOf lib.types.str;
    };
  };

  config = {
    home.file = {
      ".zsh/boot/aliases.zsh" = {
        text = ''
          ${aliasesStr}
        '';
      };
      ".zsh/boot/sourcing.zsh" = {
        text = ''
          ${sourcesStr}
        '';
      };
    };
  };
}