Skip to content

Commit bf0a143

Browse files
committed
nix: migrate to pname+version
1 parent f794cfd commit bf0a143

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

.devops/nix/package.nix

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
useMetalKit ? stdenv.isAarch64 && stdenv.isDarwin && !useOpenCL,
2525
useOpenCL ? false,
2626
useRocm ? config.rocmSupport,
27+
llamaVersion ? "0.0.0", # Arbitrary version, substituted by the flake
2728
}@inputs:
2829

2930
let
3031
inherit (lib)
3132
cmakeBool
3233
cmakeFeature
3334
optionals
35+
strings
3436
versionOlder
3537
;
3638

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

42-
# Give a little description difference between the flavors.
44+
suffices =
45+
lib.optionals useOpenCL [ "OpenCL" ]
46+
++ lib.optionals useCuda [ "CUDA" ]
47+
++ lib.optionals useRocm [ "ROCm" ]
48+
++ lib.optionals useMetalKit [ "MetalKit" ]
49+
++ lib.optionals useBlas [ "BLAS" ];
50+
51+
pnameSuffix =
52+
strings.optionalString (suffices != [ ])
53+
"-${strings.concatMapStringsSep "-" strings.toLower suffices}";
4354
descriptionSuffix =
44-
if useOpenCL then
45-
" (OpenCL accelerated)"
46-
else if useCuda then
47-
" (CUDA accelerated)"
48-
else if useRocm then
49-
" (ROCm accelerated)"
50-
else if useMetalKit then
51-
" (MetalKit accelerated)"
52-
else
53-
"";
55+
strings.optionalString (suffices != [ ])
56+
", accelerated with ${strings.concatStringsSep ", " suffices}";
5457

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

100103
effectiveStdenv.mkDerivation (
101104
finalAttrs: {
102-
name = "llama.cpp";
105+
pname = "llama-cpp${pnameSuffix}";
106+
version = llamaVersion;
107+
103108
src = ../../.;
104109

105110
postPatch = ''
@@ -171,14 +176,14 @@ effectiveStdenv.mkDerivation (
171176
;
172177

173178
shell = mkShell {
174-
name = "default${descriptionSuffix}";
179+
name = "shell-${finalAttrs.finalPackage.name}";
175180
description = "contains numpy and sentencepiece";
176181
buildInputs = [ llama-python ];
177182
inputsFrom = [ finalAttrs.finalPackage ];
178183
};
179184

180185
shell-extra = mkShell {
181-
name = "extra${descriptionSuffix}";
186+
name = "shell-extra-${finalAttrs.finalPackage.name}";
182187
description = "contains numpy, sentencepiece, torchWithoutCuda, and transformers";
183188
buildInputs = [ llama-python-extra ];
184189
inputsFrom = [ finalAttrs.finalPackage ];

.devops/nix/scope.nix

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1-
{ lib, newScope }:
1+
{
2+
lib,
3+
newScope,
4+
llamaVersion ? "0.0.0",
5+
}:
26

3-
lib.makeScope newScope (self: { llama-cpp = self.callPackage ./package.nix { }; })
7+
lib.makeScope newScope (
8+
self: {
9+
inherit llamaVersion;
10+
llama-cpp = self.callPackage ./package.nix { };
11+
}
12+
)

flake.nix

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
# { program = "/nix/store/00000000000000000000000000000000-llama.cpp/bin/quantize"; type = "app"; }
1717
# ```
1818
outputs =
19-
{ flake-parts, ... }@inputs:
19+
{ self, flake-parts, ... }@inputs:
20+
let
21+
llamaVersion = self.dirtyShortRev or self.shortRev;
22+
in
2023
flake-parts.lib.mkFlake { inherit inputs; }
2124

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

5358
systems = [
5459
"aarch64-darwin"
@@ -69,10 +74,10 @@
6974
# We don't use the overlay here so as to avoid making too many instances of nixpkgs,
7075
# cf. https://zimbatm.com/notes/1000-instances-of-nixpkgs
7176
packages = {
72-
default = (pkgs.callPackage .devops/nix/scope.nix { }).llama-cpp;
77+
default = (pkgs.callPackage .devops/nix/scope.nix { inherit llamaVersion; }).llama-cpp;
7378
opencl = config.packages.default.override { useOpenCL = true; };
74-
cuda = (pkgsCuda.callPackage .devops/nix/scope.nix { }).llama-cpp;
75-
rocm = (pkgsRocm.callPackage .devops/nix/scope.nix { }).llama-cpp;
79+
cuda = (pkgsCuda.callPackage .devops/nix/scope.nix { inherit llamaVersion; }).llama-cpp;
80+
rocm = (pkgsRocm.callPackage .devops/nix/scope.nix { inherit llamaVersion; }).llama-cpp;
7681
};
7782
};
7883
};

0 commit comments

Comments
 (0)