Skip to content

Commit 201294a

Browse files
authored
nix: init singularity and docker images (#5056)
Exposes a few attributes demonstrating how to build [singularity](https://docs.sylabs.io/guides/latest/user-guide/)/[apptainer](https://apptainer.org/) and Docker images re-using llama.cpp's Nix expression. Built locally on `x86_64-linux` with `nix build github:someoneserge/llama.cpp/feat/nix/images#llamaPackages.{docker,docker-min,sif,llama-cpp}` and it's fast and effective.
1 parent 5a9e2f6 commit 201294a

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

.devops/nix/docker.nix

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
lib,
3+
dockerTools,
4+
buildEnv,
5+
llama-cpp,
6+
interactive ? true,
7+
coreutils,
8+
}:
9+
10+
# A tar that can be fed into `docker load`:
11+
#
12+
# $ nix build .#llamaPackages.docker
13+
# $ docker load < result
14+
15+
# For details and variations cf.
16+
# - https://nixos.org/manual/nixpkgs/unstable/#ssec-pkgs-dockerTools-buildLayeredImage
17+
# - https://discourse.nixos.org/t/a-faster-dockertools-buildimage-prototype/16922
18+
# - https://nixery.dev/
19+
20+
# Approximate (compressed) sizes, at the time of writing, are:
21+
#
22+
# .#llamaPackages.docker: 125M;
23+
# .#llamaPackagesCuda.docker: 537M;
24+
# .#legacyPackages.aarch64-linux.llamaPackagesXavier.docker: 415M.
25+
26+
dockerTools.buildLayeredImage {
27+
name = llama-cpp.pname;
28+
tag = "latest";
29+
30+
contents =
31+
[ llama-cpp ]
32+
++ lib.optionals interactive [
33+
coreutils
34+
dockerTools.binSh
35+
dockerTools.caCertificates
36+
];
37+
}

.devops/nix/scope.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ lib.makeScope newScope (
1212
self: {
1313
inherit llamaVersion;
1414
llama-cpp = self.callPackage ./package.nix { };
15+
docker = self.callPackage ./docker.nix { };
16+
docker-min = self.callPackage ./docker.nix { interactive = false; };
17+
sif = self.callPackage ./sif.nix { };
1518
}
1619
)

.devops/nix/sif.nix

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
lib,
3+
singularity-tools,
4+
llama-cpp,
5+
bashInteractive,
6+
interactive ? false,
7+
}:
8+
9+
let
10+
optionalInt = cond: x: if cond then x else 0;
11+
in
12+
singularity-tools.buildImage rec {
13+
inherit (llama-cpp) name;
14+
contents = [ llama-cpp ] ++ lib.optionals interactive [ bashInteractive ];
15+
16+
# These are excessive (but safe) for most variants. Building singularity
17+
# images requires superuser privileges, so we build them inside a VM in a
18+
# writable image of pre-determined size.
19+
#
20+
# ROCm is currently affected by https://github.com/NixOS/nixpkgs/issues/276846
21+
#
22+
# Expected image sizes:
23+
# - cpu/blas: 150M,
24+
# - cuda, all gencodes: 560M,
25+
diskSize = 4096 + optionalInt llama-cpp.useRocm 16384;
26+
memSize = diskSize;
27+
}

0 commit comments

Comments
 (0)