about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/graphics/realesrgan-ncnn-vulkan/default.nix
blob: 6a3b66a3548c709b5bf3cd94927cce60b73afa9e (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
{ lib
, stdenv
, fetchzip
, fetchFromGitHub
, cmake
, vulkan-headers
, vulkan-loader
, glslang
, libwebp
, ncnn
}:

stdenv.mkDerivation rec {
  pname = "Real-ESRGAN-ncnn-vulkan";
  version = "0.2.0";

  src = fetchFromGitHub {
    owner = "xinntao";
    repo = pname;
    rev = "v${version}";
    sha256 = "sha256-F+NfkAbk8UtAKzsF42ppPF2UGjK/M6iFfBsRRBbCmcI=";
  };
  sourceRoot = "${src.name}/src";

  models = fetchzip {
    # Choose the newst release from https://github.com/xinntao/Real-ESRGAN/releases to update
    url = "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesrgan-ncnn-vulkan-20220424-ubuntu.zip";
    stripRoot = false;
    sha256 = "sha256-1YiPzv1eGnHrazJFRvl37+C1F2xnoEbN0UQYkxLT+JQ=";
  };

  patches = [
    ./cmakelists.patch
    ./models_path.patch
  ];

  cmakeFlags = [
    "-DUSE_SYSTEM_NCNN=1"
    "-DUSE_SYSTEM_WEBP=1"

    "-DGLSLANG_TARGET_DIR=${glslang}/lib/cmake"
  ];

  nativeBuildInputs = [ cmake ];
  buildInputs = [ vulkan-headers vulkan-loader glslang libwebp ncnn ];

  postPatch = ''
    substituteInPlace main.cpp --replace REPLACE_MODELS $out/share/models
  '';

  installPhase = ''
    mkdir -p $out/bin $out/share
    cp realesrgan-ncnn-vulkan $out/bin/
    cp -r ${models}/models $out/share
  '';

  meta = with lib; {
    description = "NCNN implementation of Real-ESRGAN. Real-ESRGAN aims at developing Practical Algorithms for General Image Restoration";
    homepage = "https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan";
    license = licenses.mit;
    maintainers = with maintainers; [ tilcreator ];
    platforms = platforms.all;
    mainProgram = "realesrgan-ncnn-vulkan";
  };
}