Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flake.nix: rewrite #4605

Merged
merged 23 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d3e73df
flake.lock: update to hotfix CUDA::cuda_driver
SomeoneSerge Dec 26, 2023
8364cf4
flake.nix: rewrite
philiptaron Dec 22, 2023
0607e24
flake.nix: use finalPackage instead of passing it manually
SomeoneSerge Dec 24, 2023
eab1c12
nix: unclutter darwin support
SomeoneSerge Dec 24, 2023
0259941
nix: pass most darwin frameworks unconditionally
SomeoneSerge Dec 24, 2023
0fa62c1
*.nix: nixfmt
SomeoneSerge Dec 25, 2023
69c56bc
flake.nix: add maintainers
SomeoneSerge Dec 25, 2023
a07407c
nix: move meta down to follow Nixpkgs style more closely
SomeoneSerge Dec 25, 2023
04bc417
nix: add missing meta attributes
SomeoneSerge Dec 25, 2023
d08690a
flake.nix: avoid re-evaluating nixpkgs too many times
SomeoneSerge Dec 25, 2023
a28c9ac
flake.nix: use flake-parts
SomeoneSerge Dec 25, 2023
a629371
nix: migrate to pname+version
SomeoneSerge Dec 25, 2023
e3b1ba2
flake.nix: overlay: expose both the namespace and the default attribute
SomeoneSerge Dec 25, 2023
12d4a68
ci: add the (Nix) flakestry workflow
SomeoneSerge Dec 25, 2023
a16f589
nix: cmakeFlags: explicit OFF bools
SomeoneSerge Dec 26, 2023
dd0e12c
nix: cuda: reduce runtime closure
SomeoneSerge Dec 26, 2023
4522c47
nix: fewer rebuilds
SomeoneSerge Dec 26, 2023
ae6bebc
nix: respect config.cudaCapabilities
SomeoneSerge Dec 26, 2023
1efbc6b
nix: add the impure driver's location to the DT_RUNPATHs
SomeoneSerge Dec 26, 2023
82e48e2
nix: clean sources more thoroughly
SomeoneSerge Dec 26, 2023
7bd8d8c
nix: explicit mpi support
SomeoneSerge Dec 26, 2023
d0adab6
nix: explicit jetson support
SomeoneSerge Dec 26, 2023
3f7003b
flake.nix: darwin: only expose the default
SomeoneSerge Dec 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
nix: migrate to pname+version
  • Loading branch information
SomeoneSerge committed Dec 26, 2023
commit a629371245a292f047c2bca9d2c8e9034338130a
33 changes: 19 additions & 14 deletions .devops/nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
useMetalKit ? stdenv.isAarch64 && stdenv.isDarwin && !useOpenCL,
useOpenCL ? false,
useRocm ? config.rocmSupport,
llamaVersion ? "0.0.0", # Arbitrary version, substituted by the flake
}@inputs:

let
inherit (lib)
cmakeBool
cmakeFeature
optionals
strings
versionOlder
;

Expand All @@ -39,18 +41,19 @@ let
stdenv = throw "Use effectiveStdenv instead";
effectiveStdenv = if useCuda then cudaPackages.backendStdenv else inputs.stdenv;

# Give a little description difference between the flavors.
suffices =
lib.optionals useOpenCL [ "OpenCL" ]
++ lib.optionals useCuda [ "CUDA" ]
++ lib.optionals useRocm [ "ROCm" ]
++ lib.optionals useMetalKit [ "MetalKit" ]
++ lib.optionals useBlas [ "BLAS" ];

pnameSuffix =
strings.optionalString (suffices != [ ])
"-${strings.concatMapStringsSep "-" strings.toLower suffices}";
descriptionSuffix =
if useOpenCL then
" (OpenCL accelerated)"
else if useCuda then
" (CUDA accelerated)"
else if useRocm then
" (ROCm accelerated)"
else if useMetalKit then
" (MetalKit accelerated)"
else
"";
strings.optionalString (suffices != [ ])
", accelerated with ${strings.concatStringsSep ", " suffices}";

# TODO: package the Python in this repository in a Nix-like way.
# It'd be nice to migrate to buildPythonPackage, as well as ensure this repo
Expand Down Expand Up @@ -99,7 +102,9 @@ in

effectiveStdenv.mkDerivation (
finalAttrs: {
name = "llama.cpp";
pname = "llama-cpp${pnameSuffix}";
version = llamaVersion;

src = ../../.;

postPatch = ''
Expand Down Expand Up @@ -171,14 +176,14 @@ effectiveStdenv.mkDerivation (
;

shell = mkShell {
name = "default${descriptionSuffix}";
name = "shell-${finalAttrs.finalPackage.name}";
description = "contains numpy and sentencepiece";
buildInputs = [ llama-python ];
inputsFrom = [ finalAttrs.finalPackage ];
};

shell-extra = mkShell {
name = "extra${descriptionSuffix}";
name = "shell-extra-${finalAttrs.finalPackage.name}";
description = "contains numpy, sentencepiece, torchWithoutCuda, and transformers";
buildInputs = [ llama-python-extra ];
inputsFrom = [ finalAttrs.finalPackage ];
Expand Down
13 changes: 11 additions & 2 deletions .devops/nix/scope.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{ lib, newScope }:
{
lib,
newScope,
llamaVersion ? "0.0.0",
}:

lib.makeScope newScope (self: { llama-cpp = self.callPackage ./package.nix { }; })
lib.makeScope newScope (
self: {
inherit llamaVersion;
llama-cpp = self.callPackage ./package.nix { };
}
)
15 changes: 10 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
# { program = "/nix/store/00000000000000000000000000000000-llama.cpp/bin/quantize"; type = "app"; }
# ```
outputs =
{ flake-parts, ... }@inputs:
{ self, flake-parts, ... }@inputs:
let
llamaVersion = self.dirtyShortRev or self.shortRev;
in
flake-parts.lib.mkFlake { inherit inputs; }

{
Expand Down Expand Up @@ -48,7 +51,9 @@
#
# Cf. https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html?highlight=flake#flake-format
flake.overlays.default =
(final: prev: { llamaPackages = final.callPackage .devops/nix/scope.nix { }; });
(final: prev: {
llamaPackages = final.callPackage .devops/nix/scope.nix { inherit llamaVersion; };
});

systems = [
"aarch64-darwin"
Expand All @@ -69,10 +74,10 @@
# We don't use the overlay here so as to avoid making too many instances of nixpkgs,
# cf. https://zimbatm.com/notes/1000-instances-of-nixpkgs
packages = {
default = (pkgs.callPackage .devops/nix/scope.nix { }).llama-cpp;
default = (pkgs.callPackage .devops/nix/scope.nix { inherit llamaVersion; }).llama-cpp;
opencl = config.packages.default.override { useOpenCL = true; };
cuda = (pkgsCuda.callPackage .devops/nix/scope.nix { }).llama-cpp;
rocm = (pkgsRocm.callPackage .devops/nix/scope.nix { }).llama-cpp;
cuda = (pkgsCuda.callPackage .devops/nix/scope.nix { inherit llamaVersion; }).llama-cpp;
rocm = (pkgsRocm.callPackage .devops/nix/scope.nix { inherit llamaVersion; }).llama-cpp;
};
};
};
Expand Down