|
111 | 111 | pythonRelaxDeps = [ "protobuf" ];
|
112 | 112 | });
|
113 | 113 | scikit-image = pythonPackages.scikitimage;
|
| 114 | + moto = pythonPackages.moto.overrideAttrs (old: { |
| 115 | + doCheck = false; |
| 116 | + dontUsePytestCheck = true; |
| 117 | + |
| 118 | + }); |
114 | 119 | };
|
115 | 120 | overlay_webui = nixpkgs: pythonPackages:
|
116 | 121 | {
|
|
125 | 130 | };
|
126 | 131 | overlay_invoke = nixpkgs: pythonPackages:
|
127 | 132 | let
|
128 |
| - ifNotMinVersion = pkg: ver: overlay: if ( |
129 |
| - nixlib.versionOlder pkg.version ver |
130 |
| - ) then pkg.overrideAttrs overlay else pkg; |
131 |
| - in { |
| 133 | + ifNotMinVersion = pkg: ver: overlay: |
| 134 | + if ( |
| 135 | + nixlib.versionOlder pkg.version ver |
| 136 | + ) then pkg.overrideAttrs overlay else pkg; |
| 137 | + in |
| 138 | + { |
132 | 139 | huggingface-hub = ifNotMinVersion pythonPackages.huggingface-hub
|
133 |
| - "0.13.2" ( |
134 |
| - old: rec { |
135 |
| - version = "0.14.1"; |
136 |
| - src = nixpkgs.fetchFromGitHub { |
137 |
| - owner = "huggingface"; |
138 |
| - repo = "huggingface_hub"; |
139 |
| - rev = "refs/tags/v${version}"; |
140 |
| - hash = "sha256-+BtXi+O+Ef4p4b+8FJCrZFsxX22ZYOPXylexFtsldnA="; |
141 |
| - }; |
142 |
| - propagatedBuildInputs = old.propagatedBuildInputs ++ [pythonPackages.fsspec]; |
143 |
| - }); |
| 140 | + "0.13.2" |
| 141 | + ( |
| 142 | + old: rec { |
| 143 | + version = "0.14.1"; |
| 144 | + src = nixpkgs.fetchFromGitHub { |
| 145 | + owner = "huggingface"; |
| 146 | + repo = "huggingface_hub"; |
| 147 | + rev = "refs/tags/v${version}"; |
| 148 | + hash = "sha256-+BtXi+O+Ef4p4b+8FJCrZFsxX22ZYOPXylexFtsldnA="; |
| 149 | + }; |
| 150 | + propagatedBuildInputs = old.propagatedBuildInputs ++ [ pythonPackages.fsspec ]; |
| 151 | + } |
| 152 | + ); |
144 | 153 | transformers = ifNotMinVersion pythonPackages.transformers
|
145 |
| - "4.26" ( |
146 |
| - old: rec { |
147 |
| - version = "4.28.1"; |
148 |
| - src = nixpkgs.fetchFromGitHub { |
149 |
| - inherit (old.src) owner repo; |
150 |
| - rev = "refs/tags/v${version}"; |
151 |
| - hash = "sha256-FmiuWfoFZjZf1/GbE6PmSkeshWWh+6nDj2u2PMSeDk0="; |
152 |
| - }; |
153 |
| - }); |
| 154 | + "4.26" |
| 155 | + ( |
| 156 | + old: rec { |
| 157 | + version = "4.28.1"; |
| 158 | + src = nixpkgs.fetchFromGitHub { |
| 159 | + inherit (old.src) owner repo; |
| 160 | + rev = "refs/tags/v${version}"; |
| 161 | + hash = "sha256-FmiuWfoFZjZf1/GbE6PmSkeshWWh+6nDj2u2PMSeDk0="; |
| 162 | + }; |
| 163 | + } |
| 164 | + ); |
154 | 165 | };
|
155 | 166 | overlay_pynixify = self:
|
156 | 167 | let
|
|
243 | 254 | in
|
244 | 255 | let
|
245 | 256 | nixpkgs_ = { amd ? false, nvidia ? false, webui ? false }:
|
246 |
| - import inputs.nixpkgs { |
247 |
| - inherit system; |
248 |
| - config.allowUnfree = nvidia; #CUDA is unfree. |
249 |
| - overlays = [ |
250 |
| - (final: prev: |
251 |
| - let |
252 |
| - optional = nixlib.optionalAttrs; |
253 |
| - sl = (prev.streamlit.override ({ protobuf3 = prev.protobuf; })); |
254 |
| - makePythonHook = args: final.makeSetupHook ({ passthru.provides.setupHook = true; } // args); |
255 |
| - pythonRelaxDepsHook = prev.callPackage |
256 |
| - ({ wheel }: |
257 |
| - #upstream hook doesn't work properly with non-standard wheel names |
258 |
| - #which means that some packages from pip silently fail to be overriden |
259 |
| - #https://github.com/NixOS/nixpkgs/issues/198342 |
260 |
| - makePythonHook |
261 |
| - { |
262 |
| - name = "python-relax-deps-hook"; |
263 |
| - propagatedBuildInputs = [ wheel ]; |
264 |
| - substitutions = { |
265 |
| - pythonInterpreter = nixlib.getExe prev.python3Packages.python; |
266 |
| - }; |
267 |
| - } ./python-relax-deps-hook.sh) |
268 |
| - { wheel = prev.python3.pkgs.wheel; }; |
269 |
| - in |
270 |
| - { |
271 |
| - inherit pythonRelaxDepsHook; |
272 |
| - streamlit = sl.overrideAttrs (old: { |
273 |
| - nativeBuildInputs = old.nativeBuildInputs ++ [ pythonRelaxDepsHook ]; |
274 |
| - pythonRemoveDeps = [ "protobuf" ]; |
275 |
| - }); |
276 |
| - python3 = prev.python3.override { |
277 |
| - packageOverrides = |
278 |
| - python-self: python-super: |
279 |
| - (overlay_default prev python-super) // |
280 |
| - optional amd (overlay_amd prev python-super) // |
281 |
| - optional nvidia (overlay_nvidia prev python-super) // |
282 |
| - optional webui (overlay_webui prev python-super) // |
283 |
| - optional (!webui) (overlay_invoke prev python-super) // |
284 |
| - (overlay_pynixify python-self); |
285 |
| - }; |
286 |
| - }) |
287 |
| - ]; |
288 |
| - } // { inherit nvidia; }; |
| 257 | + import inputs.nixpkgs |
| 258 | + { |
| 259 | + inherit system; |
| 260 | + config.allowUnfree = nvidia; #CUDA is unfree. |
| 261 | + overlays = [ |
| 262 | + (final: prev: |
| 263 | + let |
| 264 | + optional = nixlib.optionalAttrs; |
| 265 | + sl = (prev.streamlit.override ({ protobuf3 = prev.protobuf; })); |
| 266 | + makePythonHook = args: final.makeSetupHook ({ passthru.provides.setupHook = true; } // args); |
| 267 | + pythonRelaxDepsHook = prev.callPackage |
| 268 | + ({ wheel }: |
| 269 | + #upstream hook doesn't work properly with non-standard wheel names |
| 270 | + #which means that some packages from pip silently fail to be overriden |
| 271 | + #https://github.com/NixOS/nixpkgs/issues/198342 |
| 272 | + makePythonHook |
| 273 | + { |
| 274 | + name = "python-relax-deps-hook"; |
| 275 | + propagatedBuildInputs = [ wheel ]; |
| 276 | + substitutions = { |
| 277 | + pythonInterpreter = nixlib.getExe prev.python3Packages.python; |
| 278 | + }; |
| 279 | + } ./python-relax-deps-hook.sh) |
| 280 | + { wheel = prev.python3.pkgs.wheel; }; |
| 281 | + in |
| 282 | + { |
| 283 | + inherit pythonRelaxDepsHook; |
| 284 | + streamlit = sl.overrideAttrs (old: { |
| 285 | + nativeBuildInputs = old.nativeBuildInputs ++ [ pythonRelaxDepsHook ]; |
| 286 | + pythonRemoveDeps = [ "protobuf" ]; |
| 287 | + }); |
| 288 | + python3 = prev.python3.override { |
| 289 | + packageOverrides = |
| 290 | + python-self: python-super: |
| 291 | + (overlay_default prev python-super) // |
| 292 | + optional amd (overlay_amd prev python-super) // |
| 293 | + optional nvidia (overlay_nvidia prev python-super) // |
| 294 | + optional webui (overlay_webui prev python-super) // |
| 295 | + optional (!webui) (overlay_invoke prev python-super) // |
| 296 | + (overlay_pynixify python-self); |
| 297 | + }; |
| 298 | + }) |
| 299 | + ]; |
| 300 | + } // { inherit nvidia; }; |
289 | 301 | in
|
290 | 302 | {
|
291 | 303 | packages.${system} =
|
|
303 | 315 | pythonRelaxDeps = [ "torch" "pytorch-lightning" "flask-socketio" "flask" "dnspython" "fastapi" ];
|
304 | 316 | pythonRemoveDeps = [ "opencv-python" "flaskwebgui" "pyreadline3" ];
|
305 | 317 | postPatch = ''
|
306 |
| - # Add subprocess to the imports |
307 |
| - substituteInPlace ./ldm/invoke/config/invokeai_configure.py --replace \ |
308 |
| - 'import shutil' \ |
309 |
| -' |
310 |
| -import shutil |
311 |
| -import subprocess |
312 |
| -' |
313 |
| - # shutil.copytree will inherit the permissions of files in the /nix/store |
314 |
| - # which are read only, so we subprocess.call cp instead and tell it not to |
315 |
| - # preserve the mode |
316 |
| - substituteInPlace ./ldm/invoke/config/invokeai_configure.py --replace \ |
317 |
| - "shutil.copytree(configs_src, configs_dest, dirs_exist_ok=True)" \ |
318 |
| - "subprocess.call(f'cp -r --no-preserve=mode {configs_src}/* {configs_dest}', shell=True)" |
| 318 | + # Add subprocess to the imports |
| 319 | + substituteInPlace ./ldm/invoke/config/invokeai_configure.py --replace \ |
| 320 | + 'import shutil' \ |
| 321 | + ' |
| 322 | + import shutil |
| 323 | + import subprocess |
| 324 | + ' |
| 325 | + # shutil.copytree will inherit the permissions of files in the /nix/store |
| 326 | + # which are read only, so we subprocess.call cp instead and tell it not to |
| 327 | + # preserve the mode |
| 328 | + substituteInPlace ./ldm/invoke/config/invokeai_configure.py --replace \ |
| 329 | + "shutil.copytree(configs_src, configs_dest, dirs_exist_ok=True)" \ |
| 330 | + "subprocess.call(f'${nixpkgs.pkgs.coreutils}/bin/cp -r --no-preserve=mode {configs_src}/* {configs_dest}', shell=True)" |
319 | 331 | '';
|
320 | 332 | };
|
321 |
| - webuiF = nixpkgs: |
322 |
| - let |
323 |
| - submodel = pkg: nixpkgs.pkgs.python3.pkgs.${pkg} + "/lib/python3.10/site-packages"; |
324 |
| - taming-transformers = submodel "taming-transformers-rom1504"; |
325 |
| - k_diffusion = submodel "k-diffusion"; |
326 |
| - codeformer = (submodel "codeformer") + "/codeformer"; |
327 |
| - blip = (submodel "blip") + "/blip"; |
328 |
| - in |
329 |
| - nixpkgs.python3.pkgs.buildPythonApplication { |
330 |
| - pname = "stable-diffusion-webui"; |
331 |
| - version = "2023-03-12"; |
332 |
| - src = webui-repo; |
333 |
| - format = "other"; |
334 |
| - propagatedBuildInputs = requirementsFor { pkgs = nixpkgs; webui = true; nvidia = nixpkgs.nvidia; }; |
335 |
| - nativeBuildInputs = [ nixpkgs.pkgs.makeWrapper ]; |
336 |
| - meta.mainProgram = "flake-launch"; |
337 |
| - buildPhase = '' |
338 |
| - runHook preBuild |
339 |
| - cp -r . $out |
340 |
| - chmod -R +w $out |
341 |
| - cd $out |
| 333 | + webuiF = nixpkgs: |
| 334 | + let |
| 335 | + submodel = pkg: nixpkgs.pkgs.python3.pkgs.${pkg} + "/lib/python3.10/site-packages"; |
| 336 | + taming-transformers = submodel "taming-transformers-rom1504"; |
| 337 | + k_diffusion = submodel "k-diffusion"; |
| 338 | + codeformer = (submodel "codeformer") + "/codeformer"; |
| 339 | + blip = (submodel "blip") + "/blip"; |
| 340 | + in |
| 341 | + nixpkgs.python3.pkgs.buildPythonApplication { |
| 342 | + pname = "stable-diffusion-webui"; |
| 343 | + version = "2023-03-12"; |
| 344 | + src = webui-repo; |
| 345 | + format = "other"; |
| 346 | + propagatedBuildInputs = requirementsFor { pkgs = nixpkgs; webui = true; nvidia = nixpkgs.nvidia; }; |
| 347 | + nativeBuildInputs = [ nixpkgs.pkgs.makeWrapper ]; |
| 348 | + meta.mainProgram = "flake-launch"; |
| 349 | + buildPhase = '' |
| 350 | + runHook preBuild |
| 351 | + cp -r . $out |
| 352 | + chmod -R +w $out |
| 353 | + cd $out |
342 | 354 |
|
343 |
| - #firstly, we need to make launch.py runnable by adding python shebang |
344 |
| - cat <<-EOF > exec_launch.py.unwrapped |
345 |
| - $(echo "#!/usr/bin/python") |
346 |
| - $(cat launch.py) |
347 |
| - EOF |
348 |
| - chmod +x exec_launch.py.unwrapped |
| 355 | + #firstly, we need to make launch.py runnable by adding python shebang |
| 356 | + cat <<-EOF > exec_launch.py.unwrapped |
| 357 | + $(echo "#!/usr/bin/python") |
| 358 | + $(cat launch.py) |
| 359 | + EOF |
| 360 | + chmod +x exec_launch.py.unwrapped |
349 | 361 |
|
350 |
| - #creating wrapper around launch.py with PYTHONPATH correctly set |
351 |
| - makeWrapper "$(pwd)/exec_launch.py.unwrapped" exec_launch.py \ |
352 |
| - --set-default PYTHONPATH $PYTHONPATH |
| 362 | + #creating wrapper around launch.py with PYTHONPATH correctly set |
| 363 | + makeWrapper "$(pwd)/exec_launch.py.unwrapped" exec_launch.py \ |
| 364 | + --set-default PYTHONPATH $PYTHONPATH |
353 | 365 |
|
354 |
| - mkdir $out/bin |
355 |
| - pushd $out/bin |
356 |
| - ln -s ../exec_launch.py launch.py |
357 |
| - buck='$' #escaping $ inside shell inside shell is tricky |
358 |
| - #next is an additional shell wrapper, which sets sensible default args for CLI |
359 |
| - #additional arguments will be passed further |
360 |
| - cat <<-EOF > flake-launch |
361 |
| - #!/usr/bin/env bash |
362 |
| - pushd $out #For some reason, fastapi only works when current workdir is set inside the repo |
363 |
| - trap "popd" EXIT |
| 366 | + mkdir $out/bin |
| 367 | + pushd $out/bin |
| 368 | + ln -s ../exec_launch.py launch.py |
| 369 | + buck='$' #escaping $ inside shell inside shell is tricky |
| 370 | + #next is an additional shell wrapper, which sets sensible default args for CLI |
| 371 | + #additional arguments will be passed further |
| 372 | + cat <<-EOF > flake-launch |
| 373 | + #!/usr/bin/env bash |
| 374 | + pushd $out #For some reason, fastapi only works when current workdir is set inside the repo |
| 375 | + trap "popd" EXIT |
364 | 376 |
|
365 |
| - "$out/bin/launch.py" --skip-install "$buck{@}" |
366 |
| - EOF |
367 |
| - # below lie remnants of my attempt to make webui use similar paths as InvokeAI for models download |
368 |
| - # additions of such options in upstream is a welcome sign, however they're mostly ignored and therefore useless |
369 |
| - # TODO: check in 6 months, maybe it'll work |
370 |
| - # For now, your best bet is to use ZFS dataset with dedup enabled or make symlinks after the fact |
| 377 | + "$out/bin/launch.py" --skip-install "$buck{@}" |
| 378 | + EOF |
| 379 | + # below lie remnants of my attempt to make webui use similar paths as InvokeAI for models download |
| 380 | + # additions of such options in upstream is a welcome sign, however they're mostly ignored and therefore useless |
| 381 | + # TODO: check in 6 months, maybe it'll work |
| 382 | + # For now, your best bet is to use ZFS dataset with dedup enabled or make symlinks after the fact |
371 | 383 |
|
372 |
| - #--codeformer-models-path "\$mp/codeformer" \ |
373 |
| - #--gfpgan-models-path "\$mp/gfpgan" --esrgan-models-path "\$mp/esrgan" \ |
374 |
| - #--bsrgan-models-path "\$mp/bsrgan" --realesrgan-models-path "\$mp/realesrgan" \ |
375 |
| - #--clip-models-path "\$mp/clip" |
376 |
| - chmod +x flake-launch |
377 |
| - popd |
| 384 | + #--codeformer-models-path "\$mp/codeformer" \ |
| 385 | + #--gfpgan-models-path "\$mp/gfpgan" --esrgan-models-path "\$mp/esrgan" \ |
| 386 | + #--bsrgan-models-path "\$mp/bsrgan" --realesrgan-models-path "\$mp/realesrgan" \ |
| 387 | + #--clip-models-path "\$mp/clip" |
| 388 | + chmod +x flake-launch |
| 389 | + popd |
378 | 390 |
|
379 |
| - runHook postBuild |
380 |
| - ''; |
381 |
| - installPhase = '' |
382 |
| - runHook preInstall |
| 391 | + runHook postBuild |
| 392 | + ''; |
| 393 | + installPhase = '' |
| 394 | + runHook preInstall |
383 | 395 |
|
384 |
| - rm -rf repositories/ |
385 |
| - mkdir repositories |
386 |
| - pushd repositories |
387 |
| - ln -s ${inputs.stable-diffusion-repo}/ stable-diffusion-stability-ai |
388 |
| - ln -s ${taming-transformers}/ taming-transformers |
389 |
| - ln -s ${k_diffusion}/ k-diffusion |
390 |
| - ln -s ${codeformer}/ CodeFormer |
391 |
| - ln -s ${blip}/ BLIP |
392 |
| - popd |
393 |
| - runHook postInstall |
394 |
| - ''; |
395 |
| - }; |
| 396 | + rm -rf repositories/ |
| 397 | + mkdir repositories |
| 398 | + pushd repositories |
| 399 | + ln -s ${inputs.stable-diffusion-repo}/ stable-diffusion-stability-ai |
| 400 | + ln -s ${taming-transformers}/ taming-transformers |
| 401 | + ln -s ${k_diffusion}/ k-diffusion |
| 402 | + ln -s ${codeformer}/ CodeFormer |
| 403 | + ln -s ${blip}/ BLIP |
| 404 | + popd |
| 405 | + runHook postInstall |
| 406 | + ''; |
| 407 | + }; |
396 | 408 | in
|
397 | 409 | {
|
398 | 410 | invokeai = {
|
|
0 commit comments