redvault-ai/flake.nix

194 lines
6.2 KiB
Nix

{
description = "A Nix-flake-based Rust development environment";
nixConfig = {
extra-substituters = [
"https://nixcache.vlt81.de"
"https://llama-cpp.cachix.org"
"https://cuda-maintainers.cachix.org"
];
extra-trusted-public-keys = [
"nixcache.vlt81.de:nw0FfUpePtL6P3IMNT9X6oln0Wg9REZINtkkI9SisqQ="
"llama-cpp.cachix.org-1:H75X+w83wUKTIPSO1KWy9ADUrzThyGs8P5tmAbkWhQc="
"cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E="
];
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils.url = "github:numtide/flake-utils";
flake-parts.url = "github:hercules-ci/flake-parts";
devshell.url = "github:numtide/devshell";
npmlock2nix = {
url = "github:nix-community/npmlock2nix";
flake = false;
};
llama-cpp = {
url = "github:ggerganov/llama.cpp/b3896";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-parts.follows = "flake-parts";
};
};
outputs =
{ self
, nixpkgs
, rust-overlay
, flake-utils
, devshell
, npmlock2nix
, llama-cpp
, ...
}:
flake-utils.lib.eachDefaultSystem
(system:
let
overlays = [
llama-cpp.overlays.default
rust-overlay.overlays.default
devshell.overlays.default
(final: prev: {
customRustToolchain = prev.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
})
(final: prev: {
npmlock2nix = import npmlock2nix { pkgs = prev; };
})
(final: prev: {
prev.rocmPackages.clr = prev.rocmPackages.clr.overrideDerivation (oldAttrs: {
passthru = {
gpuTargets = rocmTargets;
updateScript = oldAttrs.passthru.updateScript;
impureTests = oldAttrs.passthru.impureTests;
};
});
})
];
pkgs = import nixpkgs {
inherit system overlays;
config = {
allowUnfree = true;
rocmSupport = true;
};
};
customNodeModules = pkgs.npmlock2nix.v2.node_modules {
src = ./.;
nodejs = pkgs.nodejs_20;
};
buildInputs = with pkgs; [
harfbuzz
openssl
pango
sqlite
mariadb
zlib
clang
libclang
gzip
coreutils
gdb
glib
glibc
wayland-utils
waylandpp
kdePackages.wayland
libxkbcommon
webkitgtk_4_1
libsoup_3
gtk3
libGL
wayland
];
rocmTargets = [
"gfx1100"
"gfx1102"
"gfx1103"
];
in
{
apps.devshell = self.outputs.devShells.${system}.default.flakeApp;
packages = {
cargo-leptos = pkgs.callPackage ./.nix/cargo-leptos.nix { };
# llama-cpp = pkgs.callPackage "${llama-cpp}/.devops/nix/scope.nix" { };
myllamacpp = with pkgs;
llamaPackages.llama-cpp.overrideDerivation (oldAttrs: {
# speeds up builts by only building for a needed rocmTargets...
cmakeFlags = [
(lib.cmakeBool "LLAMA_BUILD_SERVER" true)
(lib.cmakeBool "BUILD_SHARED_LIBS" true)
(lib.cmakeBool "CMAKE_SKIP_BUILD_RPATH" true)
(lib.cmakeBool "LLAMA_CURL" true)
(lib.cmakeBool "GGML_NATIVE" true)
(lib.cmakeBool "GGML_BLAS" false)
(lib.cmakeBool "GGML_CUDA" false)
(lib.cmakeBool "GGML_HIPBLAS" true)
(lib.cmakeBool "GGML_METAL" false)
(lib.cmakeBool "GGML_VULKAN" false)
(lib.cmakeBool "GGML_STATIC" false)
(lib.cmakeBool "GGML_FMA" true)
(lib.cmakeBool "GGML_F16C" true)
(lib.cmakeBool "GGML_AVX2" true)
(lib.cmakeBool "GGML_AVX512" false)
(lib.cmakeFeature "CMAKE_HIP_COMPILER" "${rocmPackages.llvm.clang}/bin/clang")
(lib.cmakeFeature "CMAKE_HIP_ARCHITECTURES" (builtins.concatStringsSep ";" rocmTargets))
];
});
};
devShells.default = pkgs.mkShell {
packages = with pkgs;
[
customNodeModules
customRustToolchain
self.packages.${system}.myllamacpp
binaryen
cacert
cargo-bloat
cargo-docset
cargo-machete
cargo-limit
cargo-deny
cargo-edit
cargo-watch
cargo-make
cargo-generate
cargo-udeps
self.packages.${system}.cargo-leptos
(wasm-bindgen-cli.override {
version = "0.2.93";
hash = "sha256-DDdu5mM3gneraM85pAepBXWn3TMofarVR4NbjMdz3r0=";
cargoHash = "sha256-birrg+XABBHHKJxfTKAMSlmTVYLmnmqMDfRnmG6g/YQ=";
})
cargo-outdated
cargo-release
calc
jre8 # needed for xmlls
dart-sass
fish
inotify-tools
leptosfmt
mold
nodejs_20
pkg-config
rustywind
sccache
sqlx-cli
unzip
]
++ buildInputs;
buildInputs = buildInputs;
shellHook = ''
# setup node-modules
export NPM_LOCAL_PREFIX=${customNodeModules}/node_modules
(ln -s $NPM_LOCAL_PREFIX ./node_modules 2>/dev/null || unlink ./node_modules) && ln -s $NPM_LOCAL_PREFIX ./node_modules 2>/dev/null
# export NIX_LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath buildInputs}:$NIX_LD_LIBRARY_PATH
export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath buildInputs}"
export LEPTOS_SASS_VERSION=1.71.0
export LEPTOS_TAILWIND_VERSION=3.4.1
export MALLOC_CONF=thp:always,metadata_thp:always
'';
};
});
}