about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/misc/terminal-colors/default.nix
blob: fc196be625e5b987b3163f3869c61e4e2756a37a (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
{ stdenv, lib, help2man, python3, fetchFromGitHub }:

stdenv.mkDerivation rec {
  pname = "terminal-colors";
  version = "3.0.2";
  outputs = [ "out" "man" ];

  src = fetchFromGitHub {
    owner = "eikenb";
    repo = pname;
    rev = "v${version}";
    hash = "sha256-KRoP/Reo5nDKJYG9zVTVpoYL7soAGMNk46vDoaLfnv4=";
  };

  buildInputs = [ python3 ];
  nativeBuildInputs = [ help2man ];

  postPatch =
    # This sed command modifies output of --version command in way that
    # makes manpage generated by help2man(1) prettier.
    ''
      sed -r -i "3s/([0-9.]+)/$pname - \1\\n/" ./$pname
    ''
    # Upstream shebang of "terminal-colors" python script uses
    # /usr/bin/env, which is not present in Nix sandbox, so we need to
    # patch it before running help2man, otherwise it would fail with "no
    # such file or directory".
    + ''
      patchShebangs ./$pname
    '';

  buildPhase = ''
    runHook preBuild

    help2man -n 'display terminal colors' -N ./$pname > $pname.1

    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    install -D -m755 ./$pname -t $out/bin
    install -D -m644 ./$pname.1 -t $man/share/man/man1

    runHook postInstall
  '';

  meta = with lib; {
    description = "Script displaying terminal colors in various formats";
    homepage = "https://github.com/eikenb/terminal-colors";
    license = licenses.gpl3Plus;
    maintainers = with maintainers; [ kaction ];
    mainProgram = "terminal-colors";
  };
}