summary refs log tree commit diff
path: root/pkgs/misc/openrussian-cli/default.nix
blob: 038bdd5a73f1a26a2450b7caaa1c8f2b360e3cb2 (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
{ stdenv, lib, fetchFromGitHub, pkg-config, wget, unzip
, sqlite, which, lua, installShellFiles, makeWrapper
}:
let
  luaEnv = lua.withPackages(p: with p; [ luasql-sqlite3 luautf8 ]);
in
stdenv.mkDerivation rec {
  pname   = "openrussian-cli";
  version = "1.0.0";

  src = fetchFromGitHub {
    owner   = "rhaberkorn";
    repo    = "openrussian-cli";
    rev     = version;
    sha256  = "1ria7s7dpqip2wdwn35wmkry84g8ghdqnxc9cbxzzq63vl6pgvcn";
  };

  nativeBuildInputs = [
    pkg-config wget unzip sqlite which installShellFiles makeWrapper
  ];

  buildInputs = [ luaEnv ];

  makeFlags = [
    "LUA=${luaEnv}/bin/lua"
    "LUAC=${luaEnv}/bin/luac"
  ];

  dontConfigure = true;

  # Can't use "make install" here
  installPhase = ''
    runHook preInstall

    mkdir -p $out/bin $out/share/openrussian
    cp openrussian-sqlite3.db $out/share/openrussian
    cp openrussian $out/bin

    wrapProgram $out/bin/openrussian \
      --prefix LUA_PATH ';' '${lua.pkgs.luaLib.genLuaPathAbsStr luaEnv}' \
      --prefix LUA_CPATH ';' '${lua.pkgs.luaLib.genLuaCPathAbsStr luaEnv}'

    runHook postInstall
  '';

  postInstall = ''
    installShellCompletion --cmd openrussian --bash ./openrussian-completion.bash
    installManPage ./openrussian.1
  '';

  meta = with lib; {
    description = "Offline Console Russian Dictionary (based on openrussian.org)";
    homepage    = "https://github.com/rhaberkorn/openrussian-cli";
    license     = with licenses; [ gpl3Only mit cc-by-sa-40 ];
    maintainers = with maintainers; [ zane ];
    mainProgram = "openrussian";
    platforms   = platforms.unix;
  };
}