1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-30 18:38:31 +02:00
home-manager/modules/programs/nnn.nix
Emily 36a53d9f26 treewide: convert all option docs to Markdown
This process was automated by [my fork of `nix-doc-munge`]. All
conversions were automatically checked to produce the same DocBook
result when converted back, modulo minor typographical/formatting
differences on the acceptable-to-desirable spectrum.

To reproduce this commit, run:

  $ NIX_PATH=nixpkgs=flake:nixpkgs/e7e69199f0372364a6106a1e735f68604f4c5a25 \
    nix shell nixpkgs#coreutils \
    -c find . -name '*.nix' \
    -exec nix run -- github:emilazy/nix-doc-munge/98dadf1f77351c2ba5dcb709a2a171d655f15099 \
    {} +
  $ ./format

[my fork of `nix-doc-munge`]: https://github.com/emilazy/nix-doc-munge/tree/home-manager
2023-07-17 18:40:56 +01:00

130 lines
3.2 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.nnn;
renderSetting = key: value: "${key}:${value}";
renderSettings = settings:
concatStringsSep ";" (mapAttrsToList renderSetting settings);
pluginModule = types.submodule ({ ... }: {
options = {
src = mkOption {
type = with types; nullOr path;
example = literalExpression ''
(pkgs.fetchFromGitHub {
owner = "jarun";
repo = "nnn";
rev = "v4.0";
sha256 = "sha256-Hpc8YaJeAzJoEi7aJ6DntH2VLkoR6ToP6tPYn3llR7k=";
}) + "/plugins";
'';
default = null;
description = lib.mdDoc ''
Path to the plugin folder.
'';
};
mappings = mkOption {
type = with types; attrsOf str;
description = lib.mdDoc ''
Key mappings to the plugins.
'';
default = { };
example = literalExpression ''
{
c = "fzcd";
f = "finder";
v = "imgview";
};
'';
};
};
});
in {
meta.maintainers = with maintainers; [ thiagokokada ];
options = {
programs.nnn = {
enable = mkEnableOption (lib.mdDoc "nnn");
package = mkOption {
type = types.package;
default = pkgs.nnn;
defaultText = literalExpression "pkgs.nnn";
example =
literalExpression "pkgs.nnn.override ({ withNerdIcons = true; });";
description = lib.mdDoc ''
Package containing the {command}`nnn` program.
'';
};
finalPackage = mkOption {
type = types.package;
readOnly = true;
visible = false;
description = lib.mdDoc ''
Resulting nnn package.
'';
};
bookmarks = mkOption {
type = with types; attrsOf str;
description = lib.mdDoc ''
Directory bookmarks.
'';
example = literalExpression ''
{
d = "~/Documents";
D = "~/Downloads";
p = "~/Pictures";
v = "~/Videos";
};
'';
default = { };
};
extraPackages = mkOption {
type = with types; listOf package;
example =
literalExpression "with pkgs; [ ffmpegthumbnailer mediainfo sxiv ]";
description = lib.mdDoc ''
Extra packages available to nnn.
'';
default = [ ];
};
plugins = mkOption {
type = pluginModule;
description = lib.mdDoc ''
Manage nnn plugins.
'';
default = { };
};
};
};
config = let
nnnPackage = cfg.package.overrideAttrs (oldAttrs: {
nativeBuildInputs = (oldAttrs.nativeBuildInputs or [ ])
++ [ pkgs.makeWrapper ];
postInstall = ''
${oldAttrs.postInstall or ""}
wrapProgram $out/bin/nnn \
--prefix PATH : "${makeBinPath cfg.extraPackages}" \
--prefix NNN_BMS : "${renderSettings cfg.bookmarks}" \
--prefix NNN_PLUG : "${renderSettings cfg.plugins.mappings}"
'';
});
in mkIf cfg.enable {
programs.nnn.finalPackage = nnnPackage;
home.packages = [ nnnPackage ];
xdg.configFile."nnn/plugins" =
mkIf (cfg.plugins.src != null) { source = cfg.plugins.src; };
};
}