summaryrefslogtreecommitdiff
path: root/pkgs/by-name/na/nano/package.nix
blob: d0b543fa0a374ea4a830018695db046143babf24 (about) (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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{
  lib,
  stdenv,
  fetchurl,
  fetchFromGitHub,
  ncurses,
  texinfo,
  writeScript,
  common-updater-scripts,
  gitMinimal,
  nix,
  coreutils,
  gnused,
  callPackage,
  file ? null,
  gettext ? null,
  enableNls ? true,
  enableTiny ? false,
}:

assert enableNls -> (gettext != null);

let
  nixSyntaxHighlight = fetchFromGitHub {
    owner = "seitz";
    repo = "nanonix";
    rev = "bf8d898efaa10dce3f7972ff765b58c353b4b4ab";
    hash = "sha256-1tJV7F+iwMPRV6FgnbTw+5m7vMhgaeXftYkr9GPR4xw=";
  };

in
stdenv.mkDerivation rec {
  pname = "nano";
  version = "8.4";

  src = fetchurl {
    url = "mirror://gnu/nano/${pname}-${version}.tar.xz";
    hash = "sha256-WtKSIrvVViTYfqZ3kosxBqdDEU1sb5tB82yXviqOYo0=";
  };

  nativeBuildInputs = [ texinfo ] ++ lib.optional enableNls gettext;
  buildInputs = [ ncurses ] ++ lib.optional (!enableTiny) file;

  outputs = [
    "out"
    "info"
  ];

  configureFlags =
    [
      "--sysconfdir=/etc"
      (lib.enableFeature enableNls "nls")
      (lib.enableFeature enableTiny "tiny")
    ]
    ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
      "gl_cv_func_strcasecmp_works=yes"
    ];

  postInstall =
    if enableTiny then
      null
    else
      ''
        cp ${nixSyntaxHighlight}/nix.nanorc $out/share/nano/
      '';

  enableParallelBuilding = true;
  strictDeps = true;

  passthru = {
    tests = {
      expect = callPackage ./test-with-expect.nix { };
    };

    updateScript = writeScript "update.sh" ''
      #!${stdenv.shell}
      set -o errexit
      PATH=${
        lib.makeBinPath [
          common-updater-scripts
          gitMinimal
          nix
          coreutils
          gnused
        ]
      }

      oldVersion="$(nix-instantiate --eval -E "with import ./. {}; lib.getVersion ${pname}" | tr -d '"')"
      latestTag="$(git -c 'versionsort.suffix=-' ls-remote --exit-code --refs --sort='version:refname' --tags git://git.savannah.gnu.org/nano.git '*' | tail --lines=1 | cut --delimiter='/' --fields=3 | sed 's|^v||g')"

      if [ ! "$oldVersion" = "$latestTag" ]; then
        update-source-version ${pname} "$latestTag" --version-key=version --print-changes
      else
        echo "${pname} is already up-to-date"
      fi
    '';
  };

  meta = with lib; {
    homepage = "https://www.nano-editor.org/";
    description = "Small, user-friendly console text editor";
    license = licenses.gpl3Plus;
    maintainers = with maintainers; [
      joachifm
      nequissimus
      sigmasquadron
    ];
    platforms = platforms.all;
    mainProgram = "nano";
  };
}