From db373a8c727cad91d375b40a6c70b11ed73bdafb Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Mon, 1 Apr 2024 13:30:45 -0400 Subject: Add nixfmt to Lint.hs nixfmt is the soon-to-be official formatter for Nix code, as per the NixOS GitHub group. So I figure I should just adopt it without worrying too much about the specifics of the formatting. I just formatted everything in one go, hence the huge diff, oh well. --- Biz/Bild/Builder.nix | 258 ++++++++++++++++++++------------------- Biz/Bild/Constants.nix | 4 +- Biz/Bild/Deps.nix | 94 +++++++------- Biz/Bild/Deps/C.nix | 4 +- Biz/Bild/Deps/accelerate.nix | 12 +- Biz/Bild/Deps/autogen.nix | 61 ++++----- Biz/Bild/Deps/bitsandbytes.nix | 48 +++----- Biz/Bild/Deps/exllama.nix | 20 +-- Biz/Bild/Deps/guile-opengl.nix | 10 +- Biz/Bild/Deps/inspekt3d.nix | 14 +-- Biz/Bild/Deps/interegular.nix | 11 +- Biz/Bild/Deps/lion-pytorch.nix | 9 +- Biz/Bild/Deps/llama-cpp.nix | 12 +- Biz/Bild/Deps/nostr-rs-relay.nix | 5 +- Biz/Bild/Deps/outlines.nix | 23 +--- Biz/Bild/Deps/perscache.nix | 22 +--- Biz/Bild/Nixpkgs.nix | 18 +-- Biz/Bild/Sources.nix | 227 +++++++++++++++++++--------------- 18 files changed, 403 insertions(+), 449 deletions(-) (limited to 'Biz/Bild') diff --git a/Biz/Bild/Builder.nix b/Biz/Bild/Builder.nix index 959d176..d2e6875 100644 --- a/Biz/Bild/Builder.nix +++ b/Biz/Bild/Builder.nix @@ -1,148 +1,158 @@ -/* -This is the library of nix builders. Some rules to follow: -- Keep this code as minimal as possible. I'd rather write Haskell than Nix, - wouldn't you? -- Try to reuse as much upstream Nix as possible. +/* This is the library of nix builders. Some rules to follow: + - Keep this code as minimal as possible. I'd rather write Haskell than Nix, + wouldn't you? + - Try to reuse as much upstream Nix as possible. */ -{ analysisJSON, nixpkgs ? import ../Bild.nix {} }: +{ analysisJSON, nixpkgs ? import ../Bild.nix { } }: with nixpkgs; let analysis = builtins.fromJSON analysisJSON; - build = _: target: let - name = target.out; - root = builtins.getEnv "CODEROOT"; - mainModule = target.mainModule; - compileLine = - lib.strings.concatStringsSep " " ([target.compiler] ++ target.compilerFlags); + build = _: target: + let + name = target.out; + root = builtins.getEnv "CODEROOT"; + mainModule = target.mainModule; + compileLine = lib.strings.concatStringsSep " " + ([ target.compiler ] ++ target.compilerFlags); - allSources = target.srcs ++ [target.quapath]; + allSources = target.srcs ++ [ target.quapath ]; - isEmpty = x: x == null || x == []; + isEmpty = x: x == null || x == [ ]; - skip = ["_" ".direnv"]; - filter = file: type: - if lib.lists.elem (builtins.baseNameOf file) skip then false - # TODO: this means any new directory will cause a rebuild. this bad. i - # should recurse into the directory and match against the srcs. for now I - # just use preBuild to delete empty dirs - else if type == "directory" then true - else if type == "regular" then lib.trivial.pipe file - [ (f: lib.strings.removePrefix "${root}/" f) - (f: lib.lists.elem f allSources) - ] - else false; + skip = [ "_" ".direnv" ]; + filter = file: type: + if lib.lists.elem (builtins.baseNameOf file) skip then + false + # TODO: this means any new directory will cause a rebuild. this bad. i + # should recurse into the directory and match against the srcs. for now I + # just use preBuild to delete empty dirs + else if type == "directory" then + true + else if type == "regular" then + lib.trivial.pipe file [ + (f: lib.strings.removePrefix "${root}/" f) + (f: lib.lists.elem f allSources) + ] + else + false; - # remove empty directories, leftover from the src filter - preBuild = "find . -type d -empty -delete"; + # remove empty directories, leftover from the src filter + preBuild = "find . -type d -empty -delete"; - src = lib.sources.cleanSourceWith {inherit filter; src = lib.sources.cleanSource root;}; + src = lib.sources.cleanSourceWith { + inherit filter; + src = lib.sources.cleanSource root; + }; - langdeps_ = - if isEmpty target.langdeps then - [] + langdeps_ = if isEmpty target.langdeps then + [ ] else - lib.attrsets.attrVals - target.langdeps - (lib.attrsets.getAttrFromPath (lib.strings.splitString "." target.packageSet) bild); + lib.attrsets.attrVals target.langdeps (lib.attrsets.getAttrFromPath + (lib.strings.splitString "." target.packageSet) bild); - sysdeps_ = - if isEmpty target.sysdeps then - [] + sysdeps_ = if isEmpty target.sysdeps then + [ ] else lib.attrsets.attrVals target.sysdeps pkgs; - rundeps_ = - if isEmpty target.rundeps then - [] + rundeps_ = if isEmpty target.rundeps then + [ ] else lib.attrsets.attrVals target.rundeps bild.pkgs; - CODEROOT = "."; + CODEROOT = "."; - builders = { - base = stdenv.mkDerivation rec { - inherit name src CODEROOT preBuild; - buildInputs = langdeps_ ++ sysdeps_; - installPhase = "install -D ${name} $out/bin/${name}"; - buildPhase = compileLine; - }; + builders = { + base = stdenv.mkDerivation rec { + inherit name src CODEROOT preBuild; + buildInputs = langdeps_ ++ sysdeps_; + installPhase = "install -D ${name} $out/bin/${name}"; + buildPhase = compileLine; + }; - haskell = stdenv.mkDerivation rec { - inherit name src CODEROOT preBuild; - nativeBuildInputs = [ makeWrapper ]; - buildInputs = sysdeps_ ++ [ - (bild.haskell.ghcWith (p: - (lib.attrsets.attrVals target.langdeps p) - )) - ]; - buildPhase = compileLine; - installPhase = '' - install -D ${name} $out/bin/${name} - wrapProgram $out/bin/${name} \ - --prefix PATH : ${lib.makeBinPath rundeps_} - ''; - }; + haskell = stdenv.mkDerivation rec { + inherit name src CODEROOT preBuild; + nativeBuildInputs = [ makeWrapper ]; + buildInputs = sysdeps_ ++ [ + (bild.haskell.ghcWith + (p: (lib.attrsets.attrVals target.langdeps p))) + ]; + buildPhase = compileLine; + installPhase = '' + install -D ${name} $out/bin/${name} + wrapProgram $out/bin/${name} \ + --prefix PATH : ${lib.makeBinPath rundeps_} + ''; + }; - c = stdenv.mkDerivation rec { - inherit name src CODEROOT preBuild; - buildInputs = langdeps_ ++ sysdeps_; - installPhase = "install -D ${name} $out/bin/${name}"; - buildPhase = lib.strings.concatStringsSep " " [ - compileLine - (if isEmpty langdeps_ then "" else - "$(pkg-config --cflags ${lib.strings.concatStringsSep " " target.langdeps})") - (if isEmpty sysdeps_ then "" else - "$(pkg-config --libs ${lib.strings.concatStringsSep " " target.sysdeps})") - ]; - }; + c = stdenv.mkDerivation rec { + inherit name src CODEROOT preBuild; + buildInputs = langdeps_ ++ sysdeps_; + installPhase = "install -D ${name} $out/bin/${name}"; + buildPhase = lib.strings.concatStringsSep " " [ + compileLine + (if isEmpty langdeps_ then + "" + else + "$(pkg-config --cflags ${ + lib.strings.concatStringsSep " " target.langdeps + })") + (if isEmpty sysdeps_ then + "" + else + "$(pkg-config --libs ${ + lib.strings.concatStringsSep " " target.sysdeps + })") + ]; + }; - python = bild.python.buildPythonApplication rec { - inherit name src CODEROOT; - propagatedBuildInputs = langdeps_ ++ sysdeps_; - buildInputs = sysdeps_; - nativeCheckInputs = [ black mypy ruff ]; - checkPhase = '' - check() { - $@ || { echo "fail: $name: $3"; exit 1; } - } - cp ${../../pyproject.toml} ./pyproject.toml - check python -m black --quiet --exclude 'setup\.py$' --check . - check ${ruff}/bin/ruff check . - touch ./py.typed - check python -m mypy \ - --explicit-package-bases \ - --no-error-summary \ - --exclude 'setup\.py$' \ - . - check python -m ${mainModule} test - ''; - preBuild = '' - # remove empty directories, leftover from the src filter - find . -type d -empty -delete - # initialize remaining dirs as python modules - find . -type d -exec touch {}/__init__.py \; - # generate a minimal setup.py - cat > setup.py << EOF - from setuptools import setup, find_packages - setup( - name='${name}', - entry_points={'console_scripts':['${name} = ${mainModule}:main']}, - version='0.0.0', - url='git://simatime.com/biz.git', - author='dev', - author_email='dev@simatime.com', - description='nil', - packages=find_packages(), - install_requires=[], - ) - EOF - ''; - pythonImportsCheck = [mainModule]; # sanity check + python = bild.python.buildPythonApplication rec { + inherit name src CODEROOT; + propagatedBuildInputs = langdeps_ ++ sysdeps_; + buildInputs = sysdeps_; + nativeCheckInputs = [ black mypy ruff ]; + checkPhase = '' + check() { + $@ || { echo "fail: $name: $3"; exit 1; } + } + cp ${../../pyproject.toml} ./pyproject.toml + check python -m black --quiet --exclude 'setup\.py$' --check . + check ${ruff}/bin/ruff check . + touch ./py.typed + check python -m mypy \ + --explicit-package-bases \ + --no-error-summary \ + --exclude 'setup\.py$' \ + . + check python -m ${mainModule} test + ''; + preBuild = '' + # remove empty directories, leftover from the src filter + find . -type d -empty -delete + # initialize remaining dirs as python modules + find . -type d -exec touch {}/__init__.py \; + # generate a minimal setup.py + cat > setup.py << EOF + from setuptools import setup, find_packages + setup( + name='${name}', + entry_points={'console_scripts':['${name} = ${mainModule}:main']}, + version='0.0.0', + url='git://simatime.com/biz.git', + author='dev', + author_email='dev@simatime.com', + description='nil', + packages=find_packages(), + install_requires=[], + ) + EOF + ''; + pythonImportsCheck = [ mainModule ]; # sanity check + }; }; - }; - in builders.${target.builder}; -# the bild caller gives us the Analysis type, which is a hashmap, but i need to -# return a single drv, so just take the first one for now. ideally i would only -# pass Target, one at a time, (perhaps parallelized in haskell land) and then i -# wouldn't need all of this let nesting + in builders.${target.builder}; + # the bild caller gives us the Analysis type, which is a hashmap, but i need to + # return a single drv, so just take the first one for now. ideally i would only + # pass Target, one at a time, (perhaps parallelized in haskell land) and then i + # wouldn't need all of this let nesting in builtins.head (lib.attrsets.mapAttrsToList build analysis) diff --git a/Biz/Bild/Constants.nix b/Biz/Bild/Constants.nix index 800946d..35fd880 100644 --- a/Biz/Bild/Constants.nix +++ b/Biz/Bild/Constants.nix @@ -1,3 +1 @@ -{ - ghcCompiler = "ghc924"; -} +{ ghcCompiler = "ghc924"; } diff --git a/Biz/Bild/Deps.nix b/Biz/Bild/Deps.nix index dcb7d50..bc4b638 100644 --- a/Biz/Bild/Deps.nix +++ b/Biz/Bild/Deps.nix @@ -2,53 +2,63 @@ _self: super: with import ./Constants.nix; let - buildCabal = sel: name: - sel.callCabal2nix name super.sources.${name} {}; - buildCabalSubdir = sel: {name, src ? super.sources.${name}, subdir ? name}: - sel.callCabal2nix name (src + "/${subdir}") {}; -in rec -{ + buildCabal = sel: name: sel.callCabal2nix name super.sources.${name} { }; + buildCabalSubdir = sel: + { name, src ? super.sources.${name}, subdir ? name }: + sel.callCabal2nix name (src + "/${subdir}") { }; +in rec { haskell = super.haskell // { packages = super.haskell.packages // { - "${ghcCompiler}" = super.haskell.packages."${ghcCompiler}".override (_old: { - overrides = with super.pkgs.haskell.lib; sel: sup: - super.overridePinnedDeps (buildCabal sel) // { - acid-state = dontCheck sup.acid-state; # mac: "too many open files" - clay = doJailbreak sup.clay; - envy = doJailbreak sup.envy; - fast-tags = sup.fast-tags.overrideAttrs (old: old // { patches = []; }); - generic-data = dontCheck sup.generic-data; # https://github.com/Lysxia/generic-data/issues/56 - readable = doJailbreak sup.readable; # why is this even being built? - servant-auth = doJailbreak (buildCabalSubdir sel {name = "servant-auth"; subdir = "servant-auth/servant-auth";}); - servant-server = doJailbreak sup.servant-server; - stripe-core = doJailbreak sup.stripe-core; - stripe-haskell = dontCheck sup.stripe-haskell; - stripe-http-client = doJailbreak (dontCheck sup.stripe-http-client); - temporary = dontCheck sup.temporary; - wai-middleware-metrics = dontCheck sup.wai-middleware-metrics; - }; - }); + "${ghcCompiler}" = super.haskell.packages."${ghcCompiler}".override + (_old: { + overrides = with super.pkgs.haskell.lib; + sel: sup: + super.overridePinnedDeps (buildCabal sel) // { + acid-state = + dontCheck sup.acid-state; # mac: "too many open files" + clay = doJailbreak sup.clay; + envy = doJailbreak sup.envy; + fast-tags = + sup.fast-tags.overrideAttrs (old: old // { patches = [ ]; }); + generic-data = dontCheck + sup.generic-data; # https://github.com/Lysxia/generic-data/issues/56 + readable = + doJailbreak sup.readable; # why is this even being built? + servant-auth = doJailbreak (buildCabalSubdir sel { + name = "servant-auth"; + subdir = "servant-auth/servant-auth"; + }); + servant-server = doJailbreak sup.servant-server; + stripe-core = doJailbreak sup.stripe-core; + stripe-haskell = dontCheck sup.stripe-haskell; + stripe-http-client = + doJailbreak (dontCheck sup.stripe-http-client); + temporary = dontCheck sup.temporary; + wai-middleware-metrics = dontCheck sup.wai-middleware-metrics; + }; + }); }; }; python3 = super.python3.override { - packageOverrides = _: pysuper: with pysuper.pkgs.python3Packages; { - exllama = callPackage ./Deps/exllama.nix { - cudaPackages = super.pkgs.cudaPackages_11_7; + packageOverrides = _: pysuper: + with pysuper.pkgs.python3Packages; { + exllama = callPackage ./Deps/exllama.nix { + cudaPackages = super.pkgs.cudaPackages_11_7; + }; + interegular = callPackage ./Deps/interegular.nix { }; + outlines = callPackage ./Deps/outlines.nix { }; + perscache = callPackage ./Deps/perscache.nix { }; }; - interegular = callPackage ./Deps/interegular.nix {}; - outlines = callPackage ./Deps/outlines.nix {}; - perscache = callPackage ./Deps/perscache.nix {}; - }; }; python3Packages = python3.pkgs; - autogen = super.callPackage ./Deps/autogen.nix {}; + autogen = super.callPackage ./Deps/autogen.nix { }; guile = super.guile_3_0; - guile-opengl = super.callPackage ./Deps/guile-opengl.nix {}; + guile-opengl = super.callPackage ./Deps/guile-opengl.nix { }; # The libfive build is broken... #inspekt3d = super.callPackage ./Deps/inspekt3d.nix {}; guix = super.pkgs.stdenv.mkDerivation rec { @@ -58,13 +68,13 @@ in rec src = super.sources.guix; buildInputs = with super.pkgs; [ guile - # guile-gcrypt - # guile-sql - # guile-zlib - # guile-lzlib - # guile-avahi - # guile-git - # guile-json + # guile-gcrypt + # guile-sql + # guile-zlib + # guile-lzlib + # guile-avahi + # guile-git + # guile-json gnutls gnumake sqlite @@ -73,7 +83,7 @@ in rec ]; }; - llama-cpp = super.callPackage ./Deps/llama-cpp.nix {}; + llama-cpp = super.callPackage ./Deps/llama-cpp.nix { }; - nostr-rs-relay = super.callPackage ./Deps/nostr-rs-relay.nix {}; + nostr-rs-relay = super.callPackage ./Deps/nostr-rs-relay.nix { }; } diff --git a/Biz/Bild/Deps/C.nix b/Biz/Bild/Deps/C.nix index 45cae1b..3f670cd 100644 --- a/Biz/Bild/Deps/C.nix +++ b/Biz/Bild/Deps/C.nix @@ -1,3 +1 @@ -[ - "libsodium" -] +[ "libsodium" ] diff --git a/Biz/Bild/Deps/accelerate.nix b/Biz/Bild/Deps/accelerate.nix index 5d00f14..be1d2fd 100644 --- a/Biz/Bild/Deps/accelerate.nix +++ b/Biz/Bild/Deps/accelerate.nix @@ -1,18 +1,10 @@ -{ fetchFromGitHub -, buildPythonPackage -, numpy -, packaging -, psutil -, pyyaml -, torch +{ fetchFromGitHub, buildPythonPackage, numpy, packaging, psutil, pyyaml, torch }: buildPythonPackage rec { name = "accelerate"; version = "0.15.0"; - propagatedBuildInputs = [ - numpy packaging psutil pyyaml torch - ]; + propagatedBuildInputs = [ numpy packaging psutil pyyaml torch ]; doCheck = false; src = fetchFromGitHub { owner = "huggingface"; diff --git a/Biz/Bild/Deps/autogen.nix b/Biz/Bild/Deps/autogen.nix index b7b034d..fc95b14 100644 --- a/Biz/Bild/Deps/autogen.nix +++ b/Biz/Bild/Deps/autogen.nix @@ -1,5 +1,6 @@ # From: https://github.com/NixOS/nixpkgs/pull/139361 -{ lib, stdenv, buildPackages, fetchurl, fetchpatch, autoreconfHook, which, pkg-config, perl, guile, libxml2 }: +{ lib, stdenv, buildPackages, fetchurl, fetchpatch, autoreconfHook, which +, pkg-config, perl, guile, libxml2 }: stdenv.mkDerivation rec { pname = "autogen"; @@ -11,11 +12,12 @@ stdenv.mkDerivation rec { }; patches = let - dp = { ver ? "1%255.18.16-4", pname, name ? (pname + ".diff"), sha256 }: fetchurl { - url = "https://salsa.debian.org/debian/autogen/-/raw/debian/${ver}" + dp = { ver ? "1%255.18.16-4", pname, name ? (pname + ".diff"), sha256 }: + fetchurl { + url = "https://salsa.debian.org/debian/autogen/-/raw/debian/${ver}" + "/debian/patches/${pname}.diff?inline=false"; - inherit name sha256; - }; + inherit name sha256; + }; in [ (dp { pname = "20_no_Werror"; @@ -33,7 +35,8 @@ stdenv.mkDerivation rec { # patch meanwhile. (fetchpatch { name = "guile-3.patch"; - url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/sys-devel/autogen/files/autogen-5.18.16-guile-3.patch?id=43bcc61c56a5a7de0eaf806efec7d8c0e4c01ae7"; + url = + "https://gitweb.gentoo.org/repo/gentoo.git/plain/sys-devel/autogen/files/autogen-5.18.16-guile-3.patch?id=43bcc61c56a5a7de0eaf806efec7d8c0e4c01ae7"; sha256 = "18d7y1f6164dm1wlh7rzbacfygiwrmbc35a7qqsbdawpkhydm5lr"; }) ]; @@ -41,37 +44,37 @@ stdenv.mkDerivation rec { outputs = [ "bin" "dev" "lib" "out" "man" "info" ]; nativeBuildInputs = [ - which pkg-config perl autoreconfHook/*patches applied*/ + which + pkg-config + perl + autoreconfHook # patches applied ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ # autogen needs a build autogen when cross-compiling - buildPackages.buildPackages.autogen buildPackages.texinfo - ]; - buildInputs = [ - guile libxml2 + buildPackages.buildPackages.autogen + buildPackages.texinfo ]; + buildInputs = [ guile libxml2 ]; preConfigure = '' export MAN_PAGE_DATE=$(date '+%Y-%m-%d' -d "@$SOURCE_DATE_EPOCH") ''; - configureFlags = - [ - # Make sure to use a static value for the timeout. If we do not set a value - # here autogen will select one based on the execution time of the configure - # phase which is not really reproducible. - # - # If you are curious about the number 78, it has been cargo-culted from - # Debian: https://salsa.debian.org/debian/autogen/-/blob/master/debian/rules#L21 - "--enable-timeout=78" - ] - ++ (lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ - "--with-libxml2=${libxml2.dev}" - "--with-libxml2-cflags=-I${libxml2.dev}/include/libxml2" - # the configure check for regcomp wants to run a host program - "libopts_cv_with_libregex=yes" - #"MAKEINFO=${buildPackages.texinfo}/bin/makeinfo" - ]) - # See: https://sourceforge.net/p/autogen/bugs/187/ + configureFlags = [ + # Make sure to use a static value for the timeout. If we do not set a value + # here autogen will select one based on the execution time of the configure + # phase which is not really reproducible. + # + # If you are curious about the number 78, it has been cargo-culted from + # Debian: https://salsa.debian.org/debian/autogen/-/blob/master/debian/rules#L21 + "--enable-timeout=78" + ] ++ (lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "--with-libxml2=${libxml2.dev}" + "--with-libxml2-cflags=-I${libxml2.dev}/include/libxml2" + # the configure check for regcomp wants to run a host program + "libopts_cv_with_libregex=yes" + #"MAKEINFO=${buildPackages.texinfo}/bin/makeinfo" + ]) + # See: https://sourceforge.net/p/autogen/bugs/187/ ++ lib.optionals stdenv.isDarwin [ "ac_cv_func_utimensat=no" ]; #doCheck = true; # not reliable diff --git a/Biz/Bild/Deps/bitsandbytes.nix b/Biz/Bild/Deps/bitsandbytes.nix index b87c0c4..eb32aac 100644 --- a/Biz/Bild/Deps/bitsandbytes.nix +++ b/Biz/Bild/Deps/bitsandbytes.nix @@ -1,16 +1,5 @@ -{ lib -, buildPythonPackage -, fetchFromGitHub -, python -, pythonOlder -, pytestCheckHook -, setuptools -, torch -, einops -, lion-pytorch -, scipy -, symlinkJoin -}: +{ lib, buildPythonPackage, fetchFromGitHub, python, pythonOlder, pytestCheckHook +, setuptools, torch, einops, lion-pytorch, scipy, symlinkJoin }: let pname = "bitsandbytes"; @@ -31,10 +20,11 @@ let cuda-native-redist = symlinkJoin { name = "cuda-native-redist-${cudaVersion}"; - paths = with cudaPackages; [ - cuda_cudart # cuda_runtime.h cuda_runtime_api.h - cuda_nvcc - ] ++ cuda-common-redist; + paths = with cudaPackages; + [ + cuda_cudart # cuda_runtime.h cuda_runtime_api.h + cuda_nvcc + ] ++ cuda-common-redist; }; cuda-redist = symlinkJoin { @@ -42,8 +32,7 @@ let paths = cuda-common-redist; }; -in -buildPythonPackage { +in buildPythonPackage { inherit pname version; format = "pyproject"; @@ -70,24 +59,23 @@ buildPythonPackage { preBuild = if torch.cudaSupport then with torch.cudaPackages; - let cudaVersion = lib.concatStrings (lib.splitVersion torch.cudaPackages.cudaMajorMinorVersion); in - ''make CUDA_VERSION=${cudaVersion} cuda${cudaMajorVersion}x'' + let + cudaVersion = lib.concatStrings + (lib.splitVersion torch.cudaPackages.cudaMajorMinorVersion); + in "make CUDA_VERSION=${cudaVersion} cuda${cudaMajorVersion}x" else - ''make CUDA_VERSION=CPU cpuonly''; + "make CUDA_VERSION=CPU cpuonly"; - nativeBuildInputs = [ setuptools ] ++ lib.optionals torch.cudaSupport [ cuda-native-redist ]; + nativeBuildInputs = [ setuptools ] + ++ lib.optionals torch.cudaSupport [ cuda-native-redist ]; buildInputs = lib.optionals torch.cudaSupport [ cuda-redist ]; - propagatedBuildInputs = [ - torch - ]; + propagatedBuildInputs = [ torch ]; - doCheck = false; # tests require CUDA and also GPU access + doCheck = false; # tests require CUDA and also GPU access nativeCheckInputs = [ pytestCheckHook einops lion-pytorch scipy ]; - pythonImportsCheck = [ - "bitsandbytes" - ]; + pythonImportsCheck = [ "bitsandbytes" ]; meta = with lib; { homepage = "https://github.com/TimDettmers/bitsandbytes"; diff --git a/Biz/Bild/Deps/exllama.nix b/Biz/Bild/Deps/exllama.nix index 1f7e529..51a05e9 100644 --- a/Biz/Bild/Deps/exllama.nix +++ b/Biz/Bild/Deps/exllama.nix @@ -1,14 +1,6 @@ -{ lib -, sources -, buildPythonPackage -, pythonOlder +{ lib, sources, buildPythonPackage, pythonOlder , torch # tested on 2.0.1 and 2.1.0 (nightly) with cu118 -, safetensors -, sentencepiece -, ninja -, cudaPackages -, addOpenGLRunpath -, which +, safetensors, sentencepiece, ninja, cudaPackages, addOpenGLRunpath, which , gcc11 # cuda 11.7 requires g++ <12 }: @@ -36,12 +28,10 @@ buildPythonPackage rec { cudaPackages.cuda_cudart ]; - propagatedBuildInputs = [ - torch safetensors sentencepiece ninja - cudaPackages.cudatoolkit - ]; + propagatedBuildInputs = + [ torch safetensors sentencepiece ninja cudaPackages.cudatoolkit ]; - doCheck = false; # no tests currently + doCheck = false; # no tests currently pythonImportsCheck = [ "exllama" "exllama.cuda_ext" diff --git a/Biz/Bild/Deps/guile-opengl.nix b/Biz/Bild/Deps/guile-opengl.nix index 34019d5..d547042 100644 --- a/Biz/Bild/Deps/guile-opengl.nix +++ b/Biz/Bild/Deps/guile-opengl.nix @@ -1,12 +1,4 @@ -{ stdenv -, lib -, fetchurl -, pkgconfig -, guile -, libGL -, libGLU -, freeglut -}: +{ stdenv, lib, fetchurl, pkgconfig, guile, libGL, libGLU, freeglut }: let name = "guile-opengl-${version}"; diff --git a/Biz/Bild/Deps/inspekt3d.nix b/Biz/Bild/Deps/inspekt3d.nix index 78393ee..d1cf60e 100644 --- a/Biz/Bild/Deps/inspekt3d.nix +++ b/Biz/Bild/Deps/inspekt3d.nix @@ -1,15 +1,5 @@ -{ stdenv -, lib -, autoreconfHook -, pkgconfig -, guile -, guile-opengl -, mesa -, glibcLocales -, libfive -, sources -}: - +{ stdenv, lib, autoreconfHook, pkgconfig, guile, guile-opengl, mesa +, glibcLocales, libfive, sources }: stdenv.mkDerivation { name = "inspekt3d-unstable"; diff --git a/Biz/Bild/Deps/interegular.nix b/Biz/Bild/Deps/interegular.nix index 8b0bc86..24065d8 100644 --- a/Biz/Bild/Deps/interegular.nix +++ b/Biz/Bild/Deps/interegular.nix @@ -1,7 +1,4 @@ -{ lib -, sources -, buildPythonPackage -}: +{ lib, sources, buildPythonPackage }: buildPythonPackage rec { pname = "interegular"; @@ -12,10 +9,8 @@ buildPythonPackage rec { propagatedBuildInputs = [ ]; - doCheck = false; # no tests currently - pythonImportsCheck = [ - "interegular" - ]; + doCheck = false; # no tests currently + pythonImportsCheck = [ "interegular" ]; meta = with lib; { description = "Allows to check regexes for overlaps."; diff --git a/Biz/Bild/Deps/lion-pytorch.nix b/Biz/Bild/Deps/lion-pytorch.nix index e23011a..7b06e78 100644 --- a/Biz/Bild/Deps/lion-pytorch.nix +++ b/Biz/Bild/Deps/lion-pytorch.nix @@ -1,9 +1,4 @@ -{ lib -, buildPythonPackage -, pythonOlder -, fetchFromGitHub -, torch -}: +{ lib, buildPythonPackage, pythonOlder, fetchFromGitHub, torch }: buildPythonPackage rec { pname = "lion-pytorch"; @@ -21,7 +16,7 @@ buildPythonPackage rec { propagatedBuildInputs = [ torch ]; pythonImportsCheck = [ "lion_pytorch" ]; - doCheck = false; # no tests currently + doCheck = false; # no tests currently meta = with lib; { description = "Optimizer tuned by Google Brain using genetic algorithms"; diff --git a/Biz/Bild/Deps/llama-cpp.nix b/Biz/Bild/Deps/llama-cpp.nix index b247252..2e2aae7 100644 --- a/Biz/Bild/Deps/llama-cpp.nix +++ b/Biz/Bild/Deps/llama-cpp.nix @@ -1,13 +1,5 @@ -{ stdenv -, sources -, python3 -, cmake -, pkgconfig -, openmpi -, cudaPackages -}: -let - llama-python = python3.withPackages (ps: with ps; [ numpy sentencepiece ]); +{ stdenv, sources, python3, cmake, pkgconfig, openmpi, cudaPackages }: +let llama-python = python3.withPackages (ps: with ps; [ numpy sentencepiece ]); in stdenv.mkDerivation { name = "llama.cpp"; version = sources.llama-cpp.rev; diff --git a/Biz/Bild/Deps/nostr-rs-relay.nix b/Biz/Bild/Deps/nostr-rs-relay.nix index bb0a1cd..0eef13f 100644 --- a/Biz/Bild/Deps/nostr-rs-relay.nix +++ b/Biz/Bild/Deps/nostr-rs-relay.nix @@ -13,10 +13,7 @@ rustPlatform.buildRustPackage rec { cargoSha256 = "sha256-3593pjc4A4NsEnE/ZYsR1vSMCvw2ZJue4EIY6cFa2WA="; - nativeBuildInputs = [ - pkg-config - openssl.dev - ]; + nativeBuildInputs = [ pkg-config openssl.dev ]; buildInputs = [ openssl.dev ]; } diff --git a/Biz/Bild/Deps/outlines.nix b/Biz/Bild/Deps/outlines.nix index 013581b..29ef41b 100644 --- a/Biz/Bild/Deps/outlines.nix +++ b/Biz/Bild/Deps/outlines.nix @@ -1,18 +1,5 @@ -{ lib -, sources -, buildPythonPackage -, interegular -, jinja2 -, lark -, numpy -, perscache -, pillow -, pydantic -, regex -, scipy -, tenacity -, torch -}: +{ lib, sources, buildPythonPackage, interegular, jinja2, lark, numpy, perscache +, pillow, pydantic, regex, scipy, tenacity, torch }: buildPythonPackage rec { pname = "outlines"; @@ -35,10 +22,8 @@ buildPythonPackage rec { torch ]; - doCheck = false; # no tests currently - pythonImportsCheck = [ - "outlines" - ]; + doCheck = false; # no tests currently + pythonImportsCheck = [ "outlines" ]; meta = with lib; { description = "Probabilistic Generative Model Programming"; diff --git a/Biz/Bild/Deps/perscache.nix b/Biz/Bild/Deps/perscache.nix index d757e1a..508a261 100644 --- a/Biz/Bild/Deps/perscache.nix +++ b/Biz/Bild/Deps/perscache.nix @@ -1,11 +1,4 @@ -{ lib -, sources -, buildPythonPackage -, beartype -, cloudpickle -, icontract -, pbr -}: +{ lib, sources, buildPythonPackage, beartype, cloudpickle, icontract, pbr }: buildPythonPackage rec { pname = "perscache"; @@ -13,18 +6,11 @@ buildPythonPackage rec { src = sources.perscache; - propagatedBuildInputs = [ - beartype - cloudpickle - icontract - pbr - ]; + propagatedBuildInputs = [ beartype cloudpickle icontract pbr ]; PBR_VERSION = version; - doCheck = false; # no tests currently - pythonImportsCheck = [ - "perscache" - ]; + doCheck = false; # no tests currently + pythonImportsCheck = [ "perscache" ]; meta = with lib; { description = '' diff --git a/Biz/Bild/Nixpkgs.nix b/Biz/Bild/Nixpkgs.nix index dff44a0..ecf50b9 100644 --- a/Biz/Bild/Nixpkgs.nix +++ b/Biz/Bild/Nixpkgs.nix @@ -13,9 +13,9 @@ in import sources.nixpkgs-stable { inherit system config; overlays = [ (_: _: { inherit sources; }) - (_: _: { unstable = import sources.nixpkgs-unstable { - inherit system config; - };}) + (_: _: { + unstable = import sources.nixpkgs-unstable { inherit system config; }; + }) (_: pkgs: { # Given a generic `builder`, will generate an attrset for all the packages # pinned by `deps` with `builder` applied to the package. This attrset can @@ -29,16 +29,18 @@ in import sources.nixpkgs-stable { # rules. This will fail if build steps have changed, or if no build # rules are available upstream. overrideSource = depName: - pkgs.${depName}.overrideAttrs (old: old // rec { - version = pkgs.sources.${depName}.version or pkgs.sources.${depName}.rev; - src = pkgs.sources.${depName}; - }); + pkgs.${depName}.overrideAttrs (old: + old // rec { + version = + pkgs.sources.${depName}.version or pkgs.sources.${depName}.rev; + src = pkgs.sources.${depName}; + }); }) (_: pkgs: # override pinned deps with our sources pkgs.overridePinnedDeps pkgs.overrideSource) (import ./Deps.nix) - (_: pkgs: { niv = import pkgs.sources.niv {}; }) + (_: pkgs: { niv = import pkgs.sources.niv { }; }) ]; } diff --git a/Biz/Bild/Sources.nix b/Biz/Bild/Sources.nix index 927683a..f7af81e 100644 --- a/Biz/Bild/Sources.nix +++ b/Biz/Bild/Sources.nix @@ -7,42 +7,59 @@ let # fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + let name' = sanitizeName name + "-src"; + in if spec.builtin or true then + builtins_fetchurl { + inherit (spec) url sha256; + name = name'; + } + else + pkgs.fetchurl { + inherit (spec) url sha256; + name = name'; + }; fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + let name' = sanitizeName name + "-src"; + in if spec.builtin or true then + builtins_fetchTarball { + name = name'; + inherit (spec) url sha256; + } + else + pkgs.fetchzip { + name = name'; + inherit (spec) url sha256; + }; fetch_git = name: spec: let - ref = - if spec ? ref then spec.ref else - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; - in - builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }; + ref = if spec ? ref then + spec.ref + else if spec ? branch then + "refs/heads/${spec.branch}" + else if spec ? tag then + "refs/tags/${spec.tag}" + else + abort + "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; + in builtins.fetchGit { + url = spec.repo; + inherit (spec) rev; + inherit ref; + }; fetch_local = spec: spec.path; - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; + fetch_builtin-tarball = name: + throw '' + [${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; + fetch_builtin-url = name: + throw '' + [${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; # # Various helpers @@ -50,72 +67,87 @@ let # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); + (concatMapStrings (s: if builtins.isList s then "-" else s) + (builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name))); # The set of packages used when specs are fetched using non-builtins. mkPkgs = sources: system: let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + sourcesNixpkgs = import + (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { + inherit system; + }; hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; hasThisAsNixpkgsPath = == ./.; - in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import {} - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; + in if builtins.hasAttr "nixpkgs" sources then + sourcesNixpkgs + else if hasNixpkgsPath && !hasThisAsNixpkgsPath then + import { } + else + abort '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; # The actual fetching function. fetch = pkgs: name: spec: - if ! builtins.hasAttr "type" spec then + if !builtins.hasAttr "type" spec then abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name + else if spec.type == "file" then + fetch_file pkgs name spec + else if spec.type == "tarball" then + fetch_tarball pkgs name spec + else if spec.type == "git" then + fetch_git name spec + else if spec.type == "local" then + fetch_local spec + else if spec.type == "builtin-tarball" then + fetch_builtin-tarball name + else if spec.type == "builtin-url" then + fetch_builtin-url name else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + abort + "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; # If the environment variable NIV_OVERRIDE_${name} is set, then use # the path directly as opposed to the fetched source. replace = name: drv: let - saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; + saneName = stringAsChars + (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + in if ersatz == "" then + drv + else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then + /. + ersatz + else + /. + builtins.getEnv "PWD" + "/${ersatz}"; # Ports of functions for older nix versions # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); + mapAttrs = builtins.mapAttrs or (f: set: + with builtins; + listToAttrs (map (attr: { + name = attr; + value = f attr set.${attr}; + }) (attrNames set))); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); + range = first: last: + if first > last then + [ ] + else + builtins.genList (n: first + n) (last - first + 1); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + stringToCharacters = s: + map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); @@ -123,48 +155,46 @@ let concatStrings = builtins.concatStringsSep ""; # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else {}; + optionalAttrs = cond: as: if cond then as else { }; # fetchTarball version that is compatible between all the versions of Nix # deadnix: skip builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchTarball attrs; + let inherit (builtins) lessThan nixVersion fetchTarball; + in if lessThan nixVersion "1.12" then + fetchTarball + ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) + else + fetchTarball attrs; # fetchurl version that is compatible between all the versions of Nix # deadnix: skip builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchurl attrs; + let inherit (builtins) lessThan nixVersion fetchurl; + in if lessThan nixVersion "1.12" then + fetchurl + ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) + else + fetchurl attrs; # Create the final "sources" from the config mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) config.sources; + mapAttrs (name: spec: + if builtins.hasAttr "outPath" spec then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); }) + config.sources; # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: rec { + mkConfig = { sourcesFile ? + if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if isNull sourcesFile then + { } + else + builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem, pkgs ? mkPkgs sources system }: rec { # The sources, i.e. the attribute set of spec name to spec inherit sources; @@ -172,5 +202,6 @@ let inherit pkgs; }; -in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } +in mkSources (mkConfig { }) // { + __functor = _: settings: mkSources (mkConfig settings); +} -- cgit v1.2.3