custom: add flake

fix uv

add package
This commit is contained in:
2025-09-21 14:01:18 +02:00
parent 7170a16b91
commit ef28a673ed
11 changed files with 3183 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
use flake
+30
View File
@@ -0,0 +1,30 @@
name: Nix CI
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
on:
- pull_request
jobs:
check:
runs-on: nix-flakes
steps:
- name: Set up attic binary cache
uses: https://git.naxdy.org/Mirror/attic-action@v0.3
with:
endpoint: '${{ vars.BINARY_CACHE_URL }}'
token: '${{ secrets.BINARY_CACHE_AUTH_KEY }}'
cache: '${{ vars.BINARY_CACHE_NAME }}'
- uses: actions/checkout@v4
- name: Fetch flake inputs
run: |
nix flake prefetch-inputs
- name: Run flake checks
run: |
nix flake check -j auto --print-build-logs --keep-going
+5
View File
@@ -4,6 +4,11 @@
/repositories
/user_data
.direnv
result
result-*
.chroma
.DS_Store
.eslintrc.js
+1
View File
@@ -0,0 +1 @@
3.12
Generated
+134
View File
@@ -0,0 +1,134 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1773389992,
"narHash": "sha256-wvfdLLWJ2I9oEpDd9PfMA8osfIZicoQ5MT1jIwNs9Tk=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "c06b4ae3d6599a672a6210b7021d699c351eebda",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1770107345,
"narHash": "sha256-tbS0Ebx2PiA1FRW8mt8oejR0qMXmziJmPaU1d4kYY9g=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "4533d9293756b63904b7238acb84ac8fe4c8c2c4",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"pyproject-build-systems": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"pyproject-nix": [
"pyproject-nix"
],
"uv2nix": [
"uv2nix"
]
},
"locked": {
"lastModified": 1772555609,
"narHash": "sha256-3BA3HnUvJSbHJAlJj6XSy0Jmu7RyP2gyB/0fL7XuEDo=",
"owner": "pyproject-nix",
"repo": "build-system-pkgs",
"rev": "c37f66a953535c394244888598947679af231863",
"type": "github"
},
"original": {
"owner": "pyproject-nix",
"repo": "build-system-pkgs",
"type": "github"
}
},
"pyproject-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1773553880,
"narHash": "sha256-wfvYZMO2NOGBw/DiYX50FFvr2pIS/hjJ9Bx0FD3LH5E=",
"owner": "pyproject-nix",
"repo": "pyproject.nix",
"rev": "3799d59a6886bed706eed9d209d7fc9db8ae9040",
"type": "github"
},
"original": {
"owner": "pyproject-nix",
"repo": "pyproject.nix",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"pyproject-build-systems": "pyproject-build-systems",
"pyproject-nix": "pyproject-nix",
"treefmt-nix": "treefmt-nix",
"uv2nix": "uv2nix"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1773297127,
"narHash": "sha256-6E/yhXP7Oy/NbXtf1ktzmU8SdVqJQ09HC/48ebEGBpk=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "71b125cd05fbfd78cab3e070b73544abe24c5016",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
},
"uv2nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"pyproject-nix": [
"pyproject-nix"
]
},
"locked": {
"lastModified": 1773359304,
"narHash": "sha256-knv2C6tIk5ysix+9TxWIenPvpB20kFjQ1CH6SJMBNsU=",
"owner": "pyproject-nix",
"repo": "uv2nix",
"rev": "27b135ea72ab1637fc5845a61c101ea66d6636d6",
"type": "github"
},
"original": {
"owner": "pyproject-nix",
"repo": "uv2nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}
+412
View File
@@ -0,0 +1,412 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
pyproject-nix = {
url = "github:pyproject-nix/pyproject.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
uv2nix = {
url = "github:pyproject-nix/uv2nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.pyproject-nix.follows = "pyproject-nix";
};
pyproject-build-systems = {
url = "github:pyproject-nix/build-system-pkgs";
inputs.pyproject-nix.follows = "pyproject-nix";
inputs.uv2nix.follows = "uv2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix.url = "github:numtide/treefmt-nix";
};
outputs =
{
self,
nixpkgs,
pyproject-nix,
uv2nix,
pyproject-build-systems,
treefmt-nix,
}:
let
supportedSystems = [ "x86_64-linux" ];
pyproject = builtins.fromTOML (builtins.readFile ./pyproject.toml);
forEachSupportedSystem =
f:
nixpkgs.lib.genAttrs supportedSystems (
system:
let
pkgs = import nixpkgs {
inherit system;
config = {
allowUnfree = true;
};
};
python = pkgs.python313;
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
overlay = workspace.mkPyprojectOverlay {
sourcePreference = "wheel";
};
# some packages don't have their dependencies declared properly, or need native libraries from other packages
fixupLibsOverlay =
final: prev:
let
packages = {
llama-cpp-binaries = {
buildInputs = [
pkgs.openssl
];
postInstall = ''
pushd "$out/${python.sitePackages}/llama_cpp_binaries/bin"
for f in ./*.so.0*; do
dest=$(echo $f | sed -E 's/(.*\.so\.[0-9])[.0-9]+/\1/g')
if [ ! -f $dest ]; then
echo "linking $f to $dest"
ln -s $f $dest
fi
done
popd
'';
preFixup = ''
addAutoPatchelfSearchPath $out/${python.sitePackages}/llama_cpp_binaries/bin
'';
};
flash-attn = {
buildInputs = [
final.torch
final.nvidia-cuda-runtime-cu12
];
};
exllamav2 = {
buildInputs = [
final.torch
final.nvidia-cuda-runtime-cu12
];
};
exllamav3 = {
buildInputs = [
final.torch
final.nvidia-cuda-runtime-cu12
];
};
markupsafe = {
buildInputs = [
final.setuptools
];
dontAutoPatchelf = true;
};
torch = {
buildInputs = [
final.nvidia-cusparse-cu12
final.nvidia-cusparselt-cu12
final.nvidia-cublas-cu12
final.nvidia-cufile-cu12
final.nvidia-cusolver-cu12
final.nvidia-cufft-cu12
final.nvidia-cuda-runtime-cu12
final.nvidia-cudnn-cu12
final.nvidia-cuda-nvrtc-cu12
final.nvidia-cuda-cupti-cu12
final.nvidia-curand-cu12
final.nvidia-nccl-cu12
];
};
bitsandbytes = {
buildInputs = [
final.nvidia-cublas-cu12
final.nvidia-cusparse-cu12
final.nvidia-nvjitlink-cu12
final.nvidia-cuda-runtime-cu12
];
ignoreDeps = [
# amd
"libhip*"
# unnecessary cuda versions
"libcu*.so.11"
"libcu*.so.13"
"libnvJitLink*.11"
"libnvJitLink*.13"
# intel
"libimf*"
"libintlc*"
"libirng*"
"libsvml*"
"libsycl*"
];
};
torchao = {
buildInputs = [
final.torch
final.nvidia-cuda-runtime-cu12
];
};
nvidia-cufile-cu12 = { };
nvidia-cusolver-cu12 = {
buildInputs = [
final.nvidia-cublas-cu12
final.nvidia-cusparse-cu12
final.nvidia-nvjitlink-cu12
];
};
nvidia-cusparse-cu12 = {
buildInputs = [
final.nvidia-nvjitlink-cu12
];
};
nvidia-nvshmem-cu12 = {
nativeBuildInputs = [
pkgs.mpi
];
};
};
ignoreDeps = [
"libmlx5.so.1"
"librdmacm.so.1"
"libibverbs.so.1"
# don't know
"libcuda.so.1"
# old cuda versions
"libcudart.so.11.0"
"libcudart.so.11"
"libcublas.so.11"
"libcublasLt.so.11"
"libcusparse.so.11"
];
in
builtins.listToAttrs (
map (name: {
inherit name;
value = prev.${name}.overrideAttrs (old: {
buildInputs = (old.buildInputs or [ ]) ++ (packages.${name}.buildInputs or [ ]);
propagatedBuildInputs =
(old.propagatedBuildInputs or [ ]) ++ (packages.${name}.propagatedBuildInputs or [ ]);
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ (packages.${name}.nativeBuildInputs or [ ]);
autoPatchelfIgnoreMissingDeps = ignoreDeps ++ (packages.${name}.ignoreDeps or [ ]);
postInstall = (old.postInstall or "") + (packages.${name}.postInstall or "");
preFixup =
(old.preFixup or "")
+ (packages.${name}.preFixup or "")
+ (pkgs.lib.optionalString
(!(packages.${name} ? dontAutoPatchelf) || (packages.${name}.dontAutoPatchelf == false))
(
builtins.concatStringsSep "\n" (
map (e: "addAutoPatchelfSearchPath \"${e}\"") (packages.${name}.buildInputs or [ ])
)
)
);
});
}) (builtins.attrNames packages)
);
pythonSet = (pkgs.callPackage pyproject-nix.build.packages { inherit python; }).overrideScope (
pkgs.lib.composeManyExtensions [
pyproject-build-systems.overlays.default
overlay
fixupLibsOverlay
(final: prev: {
text-generation-webui = prev.text-generation-webui.overrideAttrs (old: {
postInstall = (old.postInstall or "") + ''
cp -r ${./css} $out/${python.sitePackages}/css
cp -r ${./js} $out/${python.sitePackages}/js
'';
meta = {
mainProgram = "server.py";
};
});
})
]
);
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
treefmt = treefmtEval.config.build.wrapper;
in
f {
inherit
fixupLibsOverlay
overlay
pkgs
python
pythonSet
system
treefmt
treefmtEval
workspace
;
}
);
in
{
formatter = forEachSupportedSystem ({ treefmt, ... }: treefmt);
packages = forEachSupportedSystem (
{
pkgs,
pythonSet,
workspace,
...
}:
{
default =
let
inherit (pkgs.callPackages pyproject-nix.build.util { }) mkApplication;
in
mkApplication {
venv = pythonSet.mkVirtualEnv "text-generation-webui-env" workspace.deps.default;
package = pythonSet.text-generation-webui;
};
}
);
devShells = forEachSupportedSystem (
{
fixupLibsOverlay,
pkgs,
python,
pythonSet,
system,
treefmt,
workspace,
...
}:
{
default = self.devShells.${system}.impure;
# shell for managing uv / python deps imperatively
impure = pkgs.mkShell {
packages = [
pkgs.uv
python
treefmt
];
env = {
# Let Nix manage Python
UV_PYTHON_DOWNLOADS = "never";
UV_PYTHON = python.interpreter;
# Python libraries often load native shared objects using dlopen(3).
# Setting LD_LIBRARY_PATH makes the dynamic library loader aware of libraries without using RPATH for lookup.
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath pkgs.pythonManylinuxPackages.manylinux1;
};
shellHook = ''
# Needed for Pytorch to find cuda libraries
export LD_LIBRARY_PATH=/run/opengl-driver/lib:$LD_LIBRARY_PATH
# Undo dependency propagation by nixpkgs.
unset PYTHONPATH
if [ -f ./.venv/bin/activate ]; then
source ./.venv/bin/activate
fi
'';
};
# fully declarative development shell with all deps managed by nix
uv2nix =
let
editableOverlay = workspace.mkEditablePyprojectOverlay {
root = "$REPO_ROOT";
};
editablePythonSet = pythonSet.overrideScope (
pkgs.lib.composeManyExtensions [
editableOverlay
fixupLibsOverlay
(final: prev: {
${pyproject.project.name} = prev.${pyproject.project.name}.overrideAttrs (old: {
src = pkgs.lib.fileset.toSource {
root = old.src;
fileset = pkgs.lib.fileset.unions [
(old.src + "/pyproject.toml")
];
};
nativeBuildInputs = old.nativeBuildInputs ++ (final.resolveBuildSystem { editables = [ ]; });
});
})
]
);
virtualenv = editablePythonSet.mkVirtualEnv "${pyproject.project.name}-dev-env" workspace.deps.all;
in
pkgs.mkShell {
packages = [
pkgs.uv
treefmt
virtualenv
];
env = {
# Let Nix manage all things Python
UV_NO_SYNC = "1";
UV_PYTHON = python.interpreter;
UV_PYTHON_DOWNLOADS = "never";
TRITON_LIBCUDA_PATH = "${pkgs.lib.getLib pkgs.cudaPackages.cudatoolkit}/lib/stubs";
CUDA_HOME = "${pkgs.cudaPackages.cudatoolkit}";
CUDA_DIR = "${pkgs.cudaPackages.cudatoolkit}";
CUDATookit_ROOT = "${pkgs.cudaPackages.cudatoolkit}";
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (
pkgs.pythonManylinuxPackages.manylinux1
++ [
pkgs.cudaPackages.cudatoolkit
]
);
};
shellHook = ''
# Undo dependency propagation by nixpkgs.
unset PYTHONPATH
# Get repository root using git. This is expanded at runtime by the editable `.pth` machinery.
export REPO_ROOT=$(git rev-parse --show-toplevel)
# make sure all libraries are findable by python
for f in $(find -L "${virtualenv}/${python.sitePackages}" -type d -name "lib"); do
export LD_LIBRARY_PATH="$f:$LD_LIBRARY_PATH"
done
# Needed for Pytorch to find cuda libraries
export LD_LIBRARY_PATH=/run/opengl-driver/lib:$LD_LIBRARY_PATH
'';
};
}
);
checks = forEachSupportedSystem (
{ treefmtEval, system, ... }:
{
treefmt = treefmtEval.config.build.check self;
uv2nixShell = self.devShells.${system}.uv2nix;
}
);
};
}
+6
View File
@@ -0,0 +1,6 @@
def main():
print("Hello from text-generation-webui!")
if __name__ == "__main__":
main()
+64
View File
@@ -0,0 +1,64 @@
[project]
name = "text-generation-webui"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"accelerate==1.12.*",
"audioop-lts<1.0; python_version >= '3.13'",
"bitsandbytes==0.49.*",
"datasets",
"diffusers==0.36.*",
"einops",
"fastapi==0.112.4",
"flash-linear-attention==0.4.*",
"html2text==2025.4.15",
"huggingface-hub==1.5.*",
"jinja2==3.1.6",
"markdown",
"numpy==2.2.*",
"pandas",
"peft==0.18.*",
"Pillow>=9.5.0",
"pydantic==2.11.0",
"pymupdf==1.27.1",
"python-docx==1.1.2",
"pyyaml",
"requests",
"rich",
"safetensors==0.7.*",
"scipy",
"sentencepiece",
"tensorboard",
"torchao==0.15.*",
"transformers==5.3.*",
"tqdm",
"wandb",
"flask_cloudflared==0.0.15",
"sse-starlette==1.6.5",
"tiktoken",
"gradio",
"gradio-client",
"llama-cpp-binaries",
"exllamav3",
"flash-attn",
]
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[tool.setuptools]
packages = { find = { where = ["."] } }
[tool.setuptools.package-data]
"*" = ["css", "js"]
[tool.uv.sources]
gradio = { url = "https://github.com/oobabooga/gradio/releases/download/4.37.2-custom.9/gradio-4.37.2+custom.9-py3-none-any.whl" }
gradio-client = { url = "https://github.com/oobabooga/gradio/releases/download/4.37.2-custom.9/gradio_client-1.0.2+custom.9-py3-none-any.whl" }
llama-cpp-binaries = { url = "https://github.com/oobabooga/llama-cpp-binaries/releases/download/v0.87.0/llama_cpp_binaries-0.87.0+cu124-py3-none-linux_x86_64.whl" }
exllamav3 = { url = "https://github.com/turboderp-org/exllamav3/releases/download/v0.0.23/exllamav3-0.0.23+cu128.torch2.9.0-cp313-cp313-linux_x86_64.whl" }
flash-attn = { url = "https://github.com/kingbri1/flash-attention/releases/download/v2.8.3/flash_attn-2.8.3+cu128torch2.9.0cxx11abiFALSE-cp313-cp313-linux_x86_64.whl" }
+2
View File
@@ -1,3 +1,5 @@
#!/usr/bin/env python
import os
import shutil
import warnings
+14
View File
@@ -0,0 +1,14 @@
{ ... }:
{
# nix
programs.nixfmt.enable = true;
programs.taplo.enable = true;
programs.typos = {
enable = true;
includes = [
"*.nix"
];
};
}
Generated
+2514
View File
File diff suppressed because it is too large Load Diff