aboutsummaryrefslogtreecommitdiff
path: root/pkgs/sdcv/wrapper.nix
blob: e26c58ceb356c9a26dd3aea5c2548879f1d8c08a (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
{ lib, stdenv, makeBinaryWrapper
, sdcv-unwrapped
}:

with sdcv-unwrapped;

let

 drv = stdenv.mkDerivation rec {
    inherit pname;
    inherit version;
    inherit meta;

    nativeBuildInputs = [ sdcv-unwrapped makeBinaryWrapper ];
    dictionaries = [ /* empty and expecting override */ ];

    phases = [ "installPhase" ];
    installPhase = ''
      mkdir -p $out/bin $out/usr/share/stardict/dic
      for dic in $dictionaries; do
        for path in "$dic"/usr/share/stardict/dic/*; do
          [ -f "$path" ] || continue
          outln="$out/usr/share/stardict/dic/${"$"}{path##*/}"
          [ -e "$outln" ] && continue
          ln -sf "$path" "$outln"
        done
      done
      makeWrapper ${sdcv-unwrapped}/bin/sdcv $out/bin/sdcv \
        --set STARDICT_DATA_DIR $out/usr/share/stardict/dic
    '';

    passthru.withDictionaries = dicts: drv.overrideAttrs (oldAttrs: {
      dictionaries = dicts;
    });
  };

in drv