fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
3.2 KiB129 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6  cfg = config.programs.nnn;
7
8  renderSetting = key: value: "${key}:${value}";
9
10  renderSettings = settings:
11    concatStringsSep ";" (mapAttrsToList renderSetting settings);
12
13  pluginModule = types.submodule ({ ... }: {
14    options = {
15      src = mkOption {
16        type = with types; nullOr path;
17        example = literalExpression ''
18          (pkgs.fetchFromGitHub {
19            owner = "jarun";
20            repo = "nnn";
21            rev = "v4.0";
22            sha256 = "sha256-Hpc8YaJeAzJoEi7aJ6DntH2VLkoR6ToP6tPYn3llR7k=";
23          }) + "/plugins";
24        '';
25        default = null;
26        description = ''
27          Path to the plugin folder.
28        '';
29      };
30
31      mappings = mkOption {
32        type = with types; attrsOf str;
33        description = ''
34          Key mappings to the plugins.
35        '';
36        default = { };
37        example = literalExpression ''
38          {
39            c = "fzcd";
40            f = "finder";
41            v = "imgview";
42          };
43        '';
44      };
45    };
46  });
47in {
48  meta.maintainers = with maintainers; [ thiagokokada ];
49
50  options = {
51    programs.nnn = {
52      enable = mkEnableOption "nnn";
53
54      package = mkOption {
55        type = types.package;
56        default = pkgs.nnn;
57        defaultText = literalExpression "pkgs.nnn";
58        example =
59          literalExpression "pkgs.nnn.override ({ withNerdIcons = true; });";
60        description = ''
61          Package containing the {command}`nnn` program.
62        '';
63      };
64
65      finalPackage = mkOption {
66        type = types.package;
67        readOnly = true;
68        visible = false;
69        description = ''
70          Resulting nnn package.
71        '';
72      };
73
74      bookmarks = mkOption {
75        type = with types; attrsOf str;
76        description = ''
77          Directory bookmarks.
78        '';
79        example = literalExpression ''
80          {
81            d = "~/Documents";
82            D = "~/Downloads";
83            p = "~/Pictures";
84            v = "~/Videos";
85          };
86        '';
87        default = { };
88      };
89
90      extraPackages = mkOption {
91        type = with types; listOf package;
92        example =
93          literalExpression "with pkgs; [ ffmpegthumbnailer mediainfo sxiv ]";
94        description = ''
95          Extra packages available to nnn.
96        '';
97        default = [ ];
98      };
99
100      plugins = mkOption {
101        type = pluginModule;
102        description = ''
103          Manage nnn plugins.
104        '';
105        default = { };
106      };
107    };
108  };
109
110  config = let
111    nnnPackage = cfg.package.overrideAttrs (oldAttrs: {
112      nativeBuildInputs = (oldAttrs.nativeBuildInputs or [ ])
113        ++ [ pkgs.makeWrapper ];
114      postInstall = ''
115        ${oldAttrs.postInstall or ""}
116
117        wrapProgram $out/bin/nnn \
118          --prefix PATH : "${makeBinPath cfg.extraPackages}" \
119          --prefix NNN_BMS : "${renderSettings cfg.bookmarks}" \
120          --prefix NNN_PLUG : "${renderSettings cfg.plugins.mappings}"
121      '';
122    });
123  in mkIf cfg.enable {
124    programs.nnn.finalPackage = nnnPackage;
125    home.packages = [ nnnPackage ];
126    xdg.configFile."nnn/plugins" =
127      mkIf (cfg.plugins.src != null) { source = cfg.plugins.src; };
128  };
129}