From a9230b679bb13de1e2488d0d459d9d4aedb9af89 Mon Sep 17 00:00:00 2001 From: Niklas Korz Date: Mon, 13 Mar 2023 10:48:39 +0100 Subject: [PATCH] Nix: development shel, direnv and compatibility --- .envrc | 1 + .gitignore | 2 ++ default.nix | 10 ++++++++++ flake.lock | 17 +++++++++++++++++ flake.nix | 21 ++++++++++++++++----- shell.nix | 10 ++++++++++ 6 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 .envrc create mode 100644 default.nix create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 000000000..c4b17d79a --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use_flake diff --git a/.gitignore b/.gitignore index 5eb1ff1b8..6f4bea6cf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .cache/ .vs/ .vscode/ +.direnv/ .DS_Store build/ @@ -18,6 +19,7 @@ models/* /main /quantize +/result arm_neon.h compile_commands.json diff --git a/default.nix b/default.nix new file mode 100644 index 000000000..2cccff28d --- /dev/null +++ b/default.nix @@ -0,0 +1,10 @@ +(import + ( + let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { src = ./.; } +).defaultNix diff --git a/flake.lock b/flake.lock index 343996da1..aa61c91a4 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "locked": { "lastModified": 1676283394, @@ -33,6 +49,7 @@ }, "root": { "inputs": { + "flake-compat": "flake-compat", "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } diff --git a/flake.nix b/flake.nix index 6029375dc..a7e034c61 100644 --- a/flake.nix +++ b/flake.nix @@ -1,15 +1,19 @@ { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, flake-utils }: + outputs = { self, nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; - python = with pkgs; python310.withPackages (ps: with python310Packages; [ + llama-python = with pkgs; python310.withPackages (ps: with python310Packages; [ torch numpy sentencepiece @@ -18,19 +22,26 @@ { packages.default = pkgs.stdenv.mkDerivation { name = "llama.cpp"; - buildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin [ - pkgs.darwin.apple_sdk.frameworks.Accelerate + buildInputs = with pkgs; lib.optionals stdenv.isDarwin [ + darwin.apple_sdk.frameworks.Accelerate ]; src = ./.; installPhase = '' mkdir -p $out/bin mv main $out/bin/llama-cpp mv quantize $out/bin/llama-cpp-quantize - echo "#!${python}/bin/python" > $out/bin/convert-pth-to-ggml + echo "#!${llama-python}/bin/python" > $out/bin/convert-pth-to-ggml cat convert-pth-to-ggml.py >> $out/bin/convert-pth-to-ggml chmod +x $out/bin/convert-pth-to-ggml ''; }; + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + llama-python + ] ++ lib.optionals stdenv.isDarwin [ + darwin.apple_sdk.frameworks.Accelerate + ]; + }; } ); } diff --git a/shell.nix b/shell.nix new file mode 100644 index 000000000..6234bb4d6 --- /dev/null +++ b/shell.nix @@ -0,0 +1,10 @@ +(import + ( + let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { src = ./.; } +).shellNix