about summary refs log tree commit diff
path: root/pkgs/applications/file-managers/nnn/default.nix
blob: 5972139b25b506dc0d671e55bfcf786e61cdeebe (plain) (blame)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
{ lib
, stdenv
, fetchFromGitHub
, fetchpatch
, installShellFiles
, makeWrapper
, pkg-config
, file
, ncurses
, readline
, which
, musl-fts
, pcre
  # options
, conf ? null
, withIcons ? false
, withNerdIcons ? false
, withEmojis ? false
, withPcre ? false
, extraMakeFlags ? [ ]
}:

# Mutually exclusive options
assert withIcons -> (withNerdIcons == false && withEmojis == false);
assert withNerdIcons -> (withIcons == false && withEmojis == false);
assert withEmojis -> (withIcons == false && withNerdIcons == false);

stdenv.mkDerivation (finalAttrs: {
  pname = "nnn";
  version = "4.9";

  src = fetchFromGitHub {
    owner = "jarun";
    repo = "nnn";
    rev = "v${finalAttrs.version}";
    hash = "sha256-g19uI36HyzTF2YUQKFP4DE2ZBsArGryVHhX79Y0XzhU=";
  };

  patches = [
    # Nix-specific: ensure nnn passes correct arguments to the Nix file command on Darwin.
    # By default, nnn expects the macOS default file command, not the one provided by Nix.
    # However, both commands use different arguments to obtain the MIME type.
    ./darwin-fix-file-mime-opts.patch
  ];

  configFile = lib.optionalString (conf != null) (builtins.toFile "nnn.h" conf);
  preBuild = lib.optionalString (conf != null) "cp ${finalAttrs.configFile} src/nnn.h";

  nativeBuildInputs = [ installShellFiles makeWrapper pkg-config ];
  buildInputs = [ readline ncurses ]
    ++ lib.optional stdenv.hostPlatform.isMusl musl-fts
    ++ lib.optional withPcre pcre;

  env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isMusl "-I${musl-fts}/include";
  NIX_LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-lfts";

  makeFlags = [ "PREFIX=$(out)" ]
    ++ lib.optionals withIcons [ "O_ICONS=1" ]
    ++ lib.optionals withNerdIcons [ "O_NERD=1" ]
    ++ lib.optionals withEmojis [ "O_EMOJI=1" ]
    ++ lib.optionals withPcre [ "O_PCRE=1" ]
    ++ extraMakeFlags;

  binPath = lib.makeBinPath [ file which ];

  installTargets = [ "install" "install-desktop" ];

  postInstall = ''
    installShellCompletion --bash --name nnn.bash misc/auto-completion/bash/nnn-completion.bash
    installShellCompletion --fish misc/auto-completion/fish/nnn.fish
    installShellCompletion --zsh misc/auto-completion/zsh/_nnn

    cp -r plugins $out/share
    cp -r misc/quitcd $out/share/quitcd

    wrapProgram $out/bin/nnn --prefix PATH : "$binPath"
  '';

  meta = with lib; {
    description = "Small ncurses-based file browser forked from noice";
    homepage = "https://github.com/jarun/nnn";
    changelog = "https://github.com/jarun/nnn/blob/v${finalAttrs.version}/CHANGELOG";
    license = licenses.bsd2;
    platforms = platforms.all;
    maintainers = with maintainers; [ Br1ght0ne ];
    mainProgram = "nnn";
  };
})