Skip to content

Commit 50ba631

Browse files
authored
Nix flake (#5)
* Add nix flake setup * Add reference to nix apps provided by the nix flake Signed-off-by: Milos Gajdos <[email protected]> --------- Signed-off-by: Milos Gajdos <[email protected]>
1 parent c880ff8 commit 50ba631

File tree

6 files changed

+218
-0
lines changed

6 files changed

+218
-0
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,21 @@ Currently supported APIs:
1212
* [x] [Google Vertex AI](https://cloud.google.com/vertex-ai/docs/generative-ai/embeddings/get-text-embeddings)
1313

1414
There are also simple command line tools provided by this project that let you query the APIs for text embeddings passed in via cli flags.
15+
16+
## nix
17+
18+
The project provides a simple `nix` flake tha leverages [gomod2nix](https://github.com/nix-community/gomod2nix) for consistent Go environments and builds.
19+
20+
To get started just run
21+
```shell
22+
nix develop
23+
```
24+
25+
And you'll be dropped into development shell.
26+
27+
In addition, each command is exposed as a `nix` app so you can run them as follows:
28+
```shell
29+
nix run ".#vertexai" -- -help
30+
```
31+
32+
**NOTE:** `gomod2nix` vendors dependencies into `nix` store so every time you add a new dependency you must run `gomod2nix generate` that updates `gomod2nix.toml`

default.nix

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{ pkgs ? (
2+
let
3+
inherit (builtins) fetchTree fromJSON readFile;
4+
inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix;
5+
in
6+
import (fetchTree nixpkgs.locked) {
7+
overlays = [
8+
(import "${fetchTree gomod2nix.locked}/overlay.nix")
9+
];
10+
}
11+
)
12+
, buildGoApplication ? pkgs.buildGoApplication
13+
}:
14+
15+
buildGoApplication {
16+
pname = "go-embeddings";
17+
version = "0.1";
18+
pwd = ./.;
19+
src = ./.;
20+
modules = ./gomod2nix.toml;
21+
doCheck = false;
22+
}

flake.lock

+85
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
description = "go-embeddings nix flake";
3+
4+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
5+
inputs.flake-utils.url = "github:numtide/flake-utils";
6+
inputs.gomod2nix.url = "github:nix-community/gomod2nix";
7+
inputs.gomod2nix.inputs.nixpkgs.follows = "nixpkgs";
8+
inputs.gomod2nix.inputs.flake-utils.follows = "flake-utils";
9+
10+
outputs = { self, nixpkgs, flake-utils, gomod2nix }:
11+
(flake-utils.lib.eachDefaultSystem
12+
(system:
13+
let
14+
pkgs = nixpkgs.legacyPackages.${system};
15+
16+
# The current default sdk for macOS fails to compile go projects, so we use a newer one for now.
17+
# This has no effect on other platforms.
18+
callPackage = pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage;
19+
in
20+
{
21+
packages.default = callPackage ./. {
22+
inherit (gomod2nix.legacyPackages.${system}) buildGoApplication;
23+
};
24+
devShells.default = callPackage ./shell.nix {
25+
inherit (gomod2nix.legacyPackages.${system}) mkGoEnv gomod2nix;
26+
};
27+
apps = {
28+
cohere = {
29+
type = "app";
30+
program = "${self.packages.${system}.default}/bin/cohere";
31+
};
32+
openai = {
33+
type = "app";
34+
program = "${self.packages.${system}.default}/bin/openai";
35+
};
36+
vertexai = {
37+
type = "app";
38+
program = "${self.packages.${system}.default}/bin/vertexai";
39+
};
40+
};
41+
})
42+
);
43+
}

gomod2nix.toml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
schema = 3
2+
3+
[mod]
4+
[mod."cloud.google.com/go/compute"]
5+
version = "v1.20.1"
6+
hash = "sha256-HQvSLdoSagQsuqOb/D9+xMc8nE9Y44Z30rQgd2AGEr8="
7+
[mod."cloud.google.com/go/compute/metadata"]
8+
version = "v0.2.3"
9+
hash = "sha256-kYB1FTQRdTDqCqJzSU/jJYbVUGyxbkASUKbEs36FUyU="
10+
[mod."github.com/golang/protobuf"]
11+
version = "v1.5.3"
12+
hash = "sha256-svogITcP4orUIsJFjMtp+Uv1+fKJv2Q5Zwf2dMqnpOQ="
13+
[mod."golang.org/x/net"]
14+
version = "v0.19.0"
15+
hash = "sha256-3M5rKEvJx4cO/q+06cGjR5sxF5JpnUWY0+fQttrWdT4="
16+
[mod."golang.org/x/oauth2"]
17+
version = "v0.15.0"
18+
hash = "sha256-exA/abu6WOR7Cwqa41LpnTD2xQNRZMYU5CnBKvXHx8Y="
19+
[mod."google.golang.org/appengine"]
20+
version = "v1.6.7"
21+
hash = "sha256-zIxGRHiq4QBvRqkrhMGMGCaVL4iM4TtlYpAi/hrivS4="
22+
[mod."google.golang.org/protobuf"]
23+
version = "v1.31.0"
24+
hash = "sha256-UdIk+xRaMfdhVICvKRk1THe3R1VU+lWD8hqoW/y8jT0="

shell.nix

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{ pkgs ? (
2+
let
3+
inherit (builtins) fetchTree fromJSON readFile;
4+
inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix;
5+
in
6+
import (fetchTree nixpkgs.locked) {
7+
overlays = [
8+
(import "${fetchTree gomod2nix.locked}/overlay.nix")
9+
];
10+
}
11+
)
12+
, mkGoEnv ? pkgs.mkGoEnv
13+
, gomod2nix ? pkgs.gomod2nix
14+
, golangci-lint ? pkgs.golangci-lint
15+
}:
16+
17+
let
18+
goEnv = mkGoEnv { pwd = ./.; };
19+
in
20+
pkgs.mkShell {
21+
packages = [
22+
goEnv
23+
gomod2nix
24+
golangci-lint
25+
];
26+
}

0 commit comments

Comments
 (0)