custom: add flake

fix uv

add package
This commit is contained in:
2025-09-21 14:01:18 +02:00
parent 042b828c73
commit c8c4c00408
11 changed files with 3978 additions and 0 deletions

1
.envrc Normal file
View File

@@ -0,0 +1 @@
use flake

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
.gitignore vendored
View File

@@ -4,6 +4,11 @@
/repositories
/user_data
.direnv
result
result-*
.chroma
.DS_Store
.eslintrc.js

1
.python-version Normal file
View File

@@ -0,0 +1 @@
3.12

134
flake.lock generated Normal file
View File

@@ -0,0 +1,134 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1758277210,
"narHash": "sha256-iCGWf/LTy+aY0zFu8q12lK8KuZp7yvdhStehhyX1v8w=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "8eaee110344796db060382e15d3af0a9fc396e0e",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1754340878,
"narHash": "sha256-lgmUyVQL9tSnvvIvBp7x1euhkkCho7n3TMzgjdvgPoU=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "cab778239e705082fe97bb4990e0d24c50924c04",
"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": 1757296493,
"narHash": "sha256-6nzSZl28IwH2Vx8YSmd3t6TREHpDbKlDPK+dq1LKIZQ=",
"owner": "pyproject-nix",
"repo": "build-system-pkgs",
"rev": "5b8e37fe0077db5c1df3a5ee90a651345f085d38",
"type": "github"
},
"original": {
"owner": "pyproject-nix",
"repo": "build-system-pkgs",
"type": "github"
}
},
"pyproject-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1758265079,
"narHash": "sha256-amLaLNwKSZPShQHzfgmc/9o76dU8xzN0743dWgvYlr8=",
"owner": "pyproject-nix",
"repo": "pyproject.nix",
"rev": "02e9418fd4af638447dca4b17b1280da95527fc9",
"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": 1758206697,
"narHash": "sha256-/DbPkh6PZOgfueCbs3uzlk4ASU2nPPsiVWhpMCNkAd0=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "128222dc911b8e2e18939537bed1762b7f3a04aa",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
},
"uv2nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"pyproject-nix": [
"pyproject-nix"
]
},
"locked": {
"lastModified": 1758170327,
"narHash": "sha256-SFvm1o9QX+FZB72r5PtrborHdFMWVnbWvTyDPXf4sOI=",
"owner": "pyproject-nix",
"repo": "uv2nix",
"rev": "95e72c3af99115eb51fc963445d4e3f222d8feea",
"type": "github"
},
"original": {
"owner": "pyproject-nix",
"repo": "uv2nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

337
flake.nix Normal file
View File

@@ -0,0 +1,337 @@
{
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;
};
python = pkgs.python311;
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 = { };
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
];
};
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
];
};
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;
preFixup =
(old.preFixup or "")
+ (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";
};
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 nvidia libraries are findable by python
for f in $(find -L "${virtualenv}/${python.sitePackages}/nvidia" -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
main.py Normal file
View File

@@ -0,0 +1,6 @@
def main():
print("Hello from text-generation-webui!")
if __name__ == "__main__":
main()

59
pyproject.toml Normal file
View File

@@ -0,0 +1,59 @@
[project]
name = "text-generation-webui"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"accelerate==1.8.*",
"bitsandbytes==0.46.*",
"colorama>=0.4.6",
"datasets>=4.1.1",
"einops>=0.8.1",
"exllamav2",
"exllamav3",
"fastapi==0.112.4",
"flash-attn",
"flask-cloudflared==0.0.14",
"gradio==4.37.*",
"html2text==2025.4.15",
"jinja2==3.1.6",
"llama-cpp-binaries ",
"markdown>=3.9",
"numpy==2.2.*",
"pandas>=2.3.2",
"peft==0.17.*",
"pillow>=9.5.0",
"psutil>=7.1.0",
"pydantic==2.8.2",
"pypdf2==3.0.1",
"python-docx==1.1.2",
"pyyaml>=6.0.2",
"requests>=2.32.5",
"rich>=14.1.0",
"safetensors==0.6.*",
"scipy>=1.16.2",
"sentencepiece>=0.2.1",
"sse-starlette==1.6.5",
"tensorboard>=2.20.0",
"tiktoken>=0.11.0",
"tqdm>=4.67.1",
"transformers==4.56.*",
"wandb>=0.22.0",
]
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[tool.setuptools]
packages = { find = { where = ["."] } }
[tool.setuptools.package-data]
"*" = ["css", "js"]
[tool.uv.sources]
llama-cpp-binaries = { url = "https://github.com/oobabooga/llama-cpp-binaries/releases/download/v0.46.0/llama_cpp_binaries-0.46.0+cu124-py3-none-linux_x86_64.whl" }
exllamav3 = { url = "https://github.com/turboderp-org/exllamav3/releases/download/v0.0.6/exllamav3-0.0.6+cu128.torch2.7.0-cp311-cp311-linux_x86_64.whl" }
exllamav2 = { url = "https://github.com/turboderp-org/exllamav2/releases/download/v0.3.2/exllamav2-0.3.2-py3-none-any.whl" }
flash-attn = { url = "https://github.com/Dao-AILab/flash-attention/releases/download/v2.8.3/flash_attn-2.8.3+cu12torch2.7cxx11abiFALSE-cp311-cp311-linux_x86_64.whl" }

View File

@@ -1,3 +1,5 @@
#!/usr/bin/env python
import os
import shutil
import warnings

14
treefmt.nix Normal file
View File

@@ -0,0 +1,14 @@
{ ... }:
{
# nix
programs.nixfmt.enable = true;
programs.taplo.enable = true;
programs.typos = {
enable = true;
includes = [
"*.nix"
];
};
}

3389
uv.lock generated Normal file

File diff suppressed because it is too large Load Diff