From 73db838c15264acf40864f5fa641b44c9c5ea5ff Mon Sep 17 00:00:00 2001 From: Grimmauld Date: Fri, 15 Nov 2024 16:42:36 +0100 Subject: [PATCH 1/3] python312Packages.vulkan: init at 1.3.275.1 --- .../python-modules/vulkan/default.nix | 63 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 2 + 2 files changed, 65 insertions(+) create mode 100644 pkgs/development/python-modules/vulkan/default.nix diff --git a/pkgs/development/python-modules/vulkan/default.nix b/pkgs/development/python-modules/vulkan/default.nix new file mode 100644 index 000000000000..a0479a50f7ab --- /dev/null +++ b/pkgs/development/python-modules/vulkan/default.nix @@ -0,0 +1,63 @@ +{ + buildPythonPackage, + cffi, + fetchFromGitHub, + inflection, + jinja2, + lib, + pysdl2, + setuptools, + vulkan-loader, + wheel, + xmltodict, +}: + +buildPythonPackage rec { + pname = "vulkan"; + version = "1.3.275.1"; + pyproject = true; + + src = fetchFromGitHub { + owner = "realitix"; + repo = "vulkan"; + rev = "refs/tags/${version}"; + hash = "sha256-b1jHNKdHF7pIC6H4O2yxy36Ppb60J0uN2P0WaCw51Gc="; + }; + + postPatch = '' + substituteInPlace vulkan/_vulkan.py \ + --replace-fail 'lib = ffi.dlopen(name)' 'lib = ffi.dlopen("${vulkan-loader}/lib/" + name)' + ''; + + buildInputs = [ + vulkan-loader + ]; + + build-system = [ + setuptools + wheel + ]; + + dependencies = [ + inflection + jinja2 + pysdl2 + xmltodict + cffi + ]; + + pythonImportsCheck = [ + "vulkan" + ]; + + meta = { + description = "Ultimate Python binding for Vulkan API"; + homepage = "https://github.com/realitix/vulkan"; + license = lib.licenses.asl20; + platforms = lib.platforms.linux; + maintainers = with lib.maintainers; [ + grimmauld + getchoo + ]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index bae65926011a..602fc91c0905 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -17549,6 +17549,8 @@ self: super: with self; { vulcan-api = callPackage ../development/python-modules/vulcan-api { }; + vulkan = callPackage ../development/python-modules/vulkan { }; + vultr = callPackage ../development/python-modules/vultr { }; vulture = callPackage ../development/python-modules/vulture { }; From 6da00ff00301b1e743e31061881b3a618be50b3f Mon Sep 17 00:00:00 2001 From: Grimmauld Date: Sat, 16 Nov 2024 10:28:39 +0100 Subject: [PATCH 2/3] upscayl-ncnn: init at 20240601-103425 --- pkgs/by-name/up/upscayl-ncnn/cmakelists.patch | 27 ++++++ .../by-name/up/upscayl-ncnn/models_path.patch | 22 +++++ pkgs/by-name/up/upscayl-ncnn/package.nix | 92 +++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 pkgs/by-name/up/upscayl-ncnn/cmakelists.patch create mode 100644 pkgs/by-name/up/upscayl-ncnn/models_path.patch create mode 100644 pkgs/by-name/up/upscayl-ncnn/package.nix diff --git a/pkgs/by-name/up/upscayl-ncnn/cmakelists.patch b/pkgs/by-name/up/upscayl-ncnn/cmakelists.patch new file mode 100644 index 000000000000..00f44080cddb --- /dev/null +++ b/pkgs/by-name/up/upscayl-ncnn/cmakelists.patch @@ -0,0 +1,27 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 7e4da27..85cf911 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -106,20 +106,13 @@ if(USE_SYSTEM_NCNN) + message(STATUS "Using glslang install located at ${GLSLANG_TARGET_DIR}") + + find_package(Threads) ++ find_package(glslang REQUIRED) ++ find_package(SPIRV-Tools-opt REQUIRED) + +- include("${GLSLANG_TARGET_DIR}/OSDependentTargets.cmake") +- include("${GLSLANG_TARGET_DIR}/OGLCompilerTargets.cmake") + if(EXISTS "${GLSLANG_TARGET_DIR}/HLSLTargets.cmake") + # hlsl support can be optional + include("${GLSLANG_TARGET_DIR}/HLSLTargets.cmake") + endif() +- include("${GLSLANG_TARGET_DIR}/glslangTargets.cmake") +- include("${GLSLANG_TARGET_DIR}/SPIRVTargets.cmake") +- +- if (NOT TARGET glslang OR NOT TARGET SPIRV) +- message(WARNING "glslang or SPIRV target not found! USE_SYSTEM_NCNN will be turned off.") +- set(USE_SYSTEM_NCNN OFF) +- endif() + endif() + endif() + diff --git a/pkgs/by-name/up/upscayl-ncnn/models_path.patch b/pkgs/by-name/up/upscayl-ncnn/models_path.patch new file mode 100644 index 000000000000..410b067cfc31 --- /dev/null +++ b/pkgs/by-name/up/upscayl-ncnn/models_path.patch @@ -0,0 +1,22 @@ +diff --git a/main.cpp b/main.cpp +index 9d44c3d..40d2b27 100644 +--- a/main.cpp ++++ b/main.cpp +@@ -207,7 +207,7 @@ static void print_usage() + fprintf(stderr, " -w width resize output to a width (default=W:default), use '-r help' for more details\n"); + fprintf(stderr, " -c compress compression of the output image, default 0 and varies to 100\n"); + fprintf(stderr, " -t tile-size tile size (>=32/0=auto, default=0) can be 0,0,0 for multi-gpu\n"); +- fprintf(stderr, " -m model-path folder path to the pre-trained models. default=models\n"); ++ fprintf(stderr, " -m model-path folder path to the pre-trained models. default=REPLACE_MODELS\n"); + fprintf(stderr, " -n model-name model name (default=realesrgan-x4plus, can be realesr-animevideov3 | realesrgan-x4plus-anime | realesrnet-x4plus or any other model)\n"); + fprintf(stderr, " -g gpu-id gpu device to use (default=auto) can be 0,1,2 for multi-gpu\n"); + fprintf(stderr, " -j load:proc:save thread count for load/proc/save (default=1:2:2) can be 1:2,2,2:2 for multi-gpu\n"); +@@ -688,7 +688,7 @@ int main(int argc, char **argv) + bool resizeProvided = false; + bool hasCustomWidth = false; + std::vector tilesize; +- path_t model = PATHSTR("models"); ++ path_t model = PATHSTR("REPLACE_MODELS"); + path_t modelname = PATHSTR("realesrgan-x4plus"); + std::vector gpuid; + int jobs_load = 1; diff --git a/pkgs/by-name/up/upscayl-ncnn/package.nix b/pkgs/by-name/up/upscayl-ncnn/package.nix new file mode 100644 index 000000000000..82db79463543 --- /dev/null +++ b/pkgs/by-name/up/upscayl-ncnn/package.nix @@ -0,0 +1,92 @@ +{ + cmake, + fetchFromGitHub, + fetchzip, + glslang, + installShellFiles, + lib, + libwebp, + ncnn, + stdenv, + vulkan-headers, + vulkan-loader, +}: + +# upscayl-ncnn is a fork of /pkgs/by-name/re/realesrgan-ncnn-vulkan, so the nix package is basically the same. +stdenv.mkDerivation (finalAttrs: { + pname = "upscayl-ncnn"; + version = "20240601-103425"; + + src = fetchFromGitHub { + owner = "upscayl"; + repo = "upscayl-ncnn"; + rev = "refs/tags/${finalAttrs.version}"; + hash = "sha256-rGnjL+sU5x3VXHnvuYXVdxGmHdj9eBkIZK3CwL89lN0="; + }; + + 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"; + hash = "sha256-1YiPzv1eGnHrazJFRvl37+C1F2xnoEbN0UQYkxLT+JQ="; + stripRoot = false; + }; + + patches = [ + ./cmakelists.patch + ./models_path.patch + ]; + + sourceRoot = "${finalAttrs.src.name}/src"; + + postPatch = '' + substituteInPlace main.cpp --replace REPLACE_MODELS $out/share/models + ''; + + nativeBuildInputs = [ + cmake + glslang + installShellFiles + ]; + + cmakeFlags = [ + (lib.cmakeBool "USE_SYSTEM_NCNN" true) + (lib.cmakeBool "USE_SYSTEM_WEBP" true) + (lib.cmakeFeature "GLSLANG_TARGET_DIR" "${glslang}/lib/cmake") + ]; + + buildInputs = [ + vulkan-loader + libwebp + ncnn + vulkan-headers + glslang + ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/share + + installBin upscayl-bin + ln -s ${finalAttrs.models}/models $out/share + + runHook postInstall + ''; + + env.NIX_LDFLAGS = lib.optionalString stdenv.hostPlatform.isLinux "-rpath ${ + lib.makeLibraryPath [ vulkan-loader ] + }"; + + meta = { + changelog = "https://github.com/upscayl/upscayl-ncnn/releases/tag/${finalAttrs.version}"; + description = "Upscayl backend powered by the NCNN framework and Real-ESRGAN architecture"; + homepage = "https://github.com/upscayl/upscayl-ncnn"; + license = lib.licenses.agpl3Only; + mainProgram = "upscayl-bin"; + maintainers = with lib.maintainers; [ + grimmauld + getchoo + ]; + platforms = lib.platforms.all; + }; +}) From 3431d2041aeb318074b85e617bb7bb66fed20f19 Mon Sep 17 00:00:00 2001 From: Grimmauld Date: Sat, 16 Nov 2024 15:27:39 +0100 Subject: [PATCH 3/3] upscaler: init at 1.4.0 --- pkgs/by-name/up/upscaler/package.nix | 92 ++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 pkgs/by-name/up/upscaler/package.nix diff --git a/pkgs/by-name/up/upscaler/package.nix b/pkgs/by-name/up/upscaler/package.nix new file mode 100644 index 000000000000..c8ce29d532a3 --- /dev/null +++ b/pkgs/by-name/up/upscaler/package.nix @@ -0,0 +1,92 @@ +{ + lib, + fetchFromGitLab, + glib, + gtk4, + meson, + ninja, + gitUpdater, + desktop-file-utils, + appstream, + blueprint-compiler, + python3Packages, + pkg-config, + libadwaita, + wrapGAppsHook4, + upscayl-ncnn, +}: + +python3Packages.buildPythonApplication rec { + pname = "upscaler"; + version = "1.4.0"; + + pyproject = false; # meson instead of pyproject + + src = fetchFromGitLab { + domain = "gitlab.gnome.org"; + owner = "World"; + repo = "Upscaler"; + rev = version; + hash = "sha256-Dy8tykIbK5o0XulurG+TxORZZSxfRe5Kjh6aGpsh+0Y="; + }; + + passthru.updateScript = gitUpdater { }; + + postPatch = '' + substituteInPlace upscaler/window.py \ + --replace-fail '"upscayl-bin",' '"${lib.getExe upscayl-ncnn}",' + ''; + + strictDeps = true; + + nativeBuildInputs = [ + wrapGAppsHook4 + meson + ninja + desktop-file-utils + appstream + blueprint-compiler + pkg-config + gtk4 + glib + ]; + + dependencies = with python3Packages; [ + pygobject3 + pillow + vulkan + ]; + + buildInputs = [ + libadwaita + upscayl-ncnn + ]; + + mesonFlags = [ + (lib.mesonBool "network_tests" false) + ]; + + # NOTE: `postCheck` is intentionally not used here, as the entire checkPhase + # is skipped by `buildPythonApplication` + # https://github.com/NixOS/nixpkgs/blob/9d4343b7b27a3e6f08fc22ead568233ff24bbbde/pkgs/development/interpreters/python/mk-python-derivation.nix#L296 + postInstallCheck = '' + mesonCheckPhase + ''; + + dontWrapGApps = true; + + makeWrapperArgs = [ "\${gappsWrapperArgs[@]}" ]; + + meta = { + description = "Upscale and enhance images"; + homepage = "https://tesk.page/upscaler"; + license = lib.licenses.gpl3Only; + maintainers = with lib.maintainers; [ + grimmauld + getchoo + aleksana + ]; + mainProgram = "upscaler"; + platforms = lib.platforms.linux; + }; +}