1{
 2  lib,
 3  singularity-tools,
 4  llama-cpp,
 5  bashInteractive,
 6  interactive ? false,
 7}:
 8
 9let
10  optionalInt = cond: x: if cond then x else 0;
11in
12singularity-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}