Skip to content

Commit 1db253c

Browse files
committed
flake.nix
Package Sourcebot with Nix, NixOS module for deployment, integration test and microvm.
1 parent 8060ade commit 1db253c

File tree

9 files changed

+950
-2
lines changed

9 files changed

+950
-2
lines changed

docs/docs/deployment-guide.mdx

Lines changed: 115 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ title: "Deployment guide"
44

55
import SupportedPlatforms from '/snippets/platform-support.mdx'
66

7+
## Container deployment
8+
79
The following guide will walk you through the steps to deploy Sourcebot on your own infrastructure. Sourcebot is distributed as a [single docker container](/docs/overview#architecture) that can be deployed to a k8s cluster, a VM, or any platform that supports docker.
810

911

10-
## Walkthrough video
12+
### Walkthrough video
1113
---
1214

1315
Watch this 1:51 minute video to get a quick overview of how to deploy Sourcebot using Docker.
@@ -21,7 +23,7 @@ Watch this 1:51 minute video to get a quick overview of how to deploy Sourcebot
2123
className="aspect-video w-full"
2224
></iframe>
2325

24-
## Step-by-step guide
26+
### Step-by-step guide
2527
---
2628

2729
<Note>Hit an issue? Please let us know on [GitHub discussions](https://github.com/sourcebot-dev/sourcebot/discussions/categories/support) or by [emailing us](mailto:[email protected]).</Note>
@@ -95,6 +97,117 @@ Watch this 1:51 minute video to get a quick overview of how to deploy Sourcebot
9597
</Step>
9698
</Steps>
9799

100+
101+
## NixOS deployment
102+
103+
<Note>Hit an issue? Please let us know on [GitHub discussions](https://github.com/sourcebot-dev/sourcebot/discussions/categories/support) or by [emailing us](mailto:[email protected]).</Note>
104+
105+
<Steps>
106+
<Step title="Flake.nix input">
107+
Add the Sourcebot flake as an input to your NixOS configuration. This will allow you to use the Sourcebot container in your NixOS deployment.
108+
109+
```nix
110+
inputs.sourcebot.url = "github:sourcebot-dev/sourcebot";
111+
```
112+
113+
Add sourcebot module to your NixOS configuration:
114+
115+
```nix
116+
nixosConfigurations.mysystem = nixpkgs.lib.nixosSystem {
117+
modules = [
118+
inputs.sourcebot.nixosModules.sourcebot
119+
];
120+
}
121+
```
122+
[Learn more about NixOS flakes](/docs/installation/nixos-flakes).
123+
</Step>
124+
<Step title="Setup Credentials">
125+
Sourcebot requires a few secrets to be set up before it can run, and code host credentials can be managed using NixOS module too:
126+
127+
- [sops-nix](https://github.com/Mic92/sops-nix) example:
128+
129+
```nix
130+
sops = {
131+
secrets = {
132+
sourcebot-auth-secret.owner = "sourcebot";
133+
sourcebot-encryption-key.owner = "sourcebot";
134+
sourcebot-gitlab-token.owner = "sourcebot";
135+
};
136+
templates = {
137+
sourcebot-env = {
138+
content = ''
139+
AUTH_SECRET=${config.sops.placeholder.sourcebot-auth-secret}
140+
SOURCEBOT_ENCRYPTION_KEY=${config.sops.placeholder.sourcebot-encryption-key}
141+
GITLAB_EXAMPLE_TOKEN=${config.sops.placeholder.sourcebot-gitlab-token}
142+
'';
143+
};
144+
};
145+
};
146+
```
147+
148+
- [agenix](https://github.com/ryantm/agenix) example:
149+
150+
```nix
151+
age.secrets.sourcebot-env.file = ../secrets/sourcebot.age;
152+
```
153+
154+
`sourcebot.age` file should be an environment file in the format:
155+
156+
```
157+
AUTH_SECRET=your-auth-secret
158+
SOURCEBOT_ENCRYPTION_KEY=your-encryption-key
159+
GITLAB_EXAMPLE_TOKEN=your-gitlab-token
160+
```
161+
</Step>
162+
<Step title="Enable Sourcebot">
163+
The following NixOS configuration will enable Sourcebot and set it up to run with the provided configuration.
164+
Additional options could be found in the [source file](../../nix/nixosModule.nix)
165+
166+
```nix
167+
services.sourcebot = {
168+
enable = true;
169+
# envFile = config.sops.templates.sourcebot-env.path; # Uncomment if using sops-nix
170+
# envFile = config.age.secrets.sourcebot-env.path; # Uncomment if using agenix
171+
package = pkgs.sourcebot;
172+
logLevel = "info";
173+
dataDir = "/data/sourcebot";
174+
dataCacheDir = "/data/sourcebot/cache";
175+
configPath = "${pkgs.writeText "config" (builtins.toJSON {
176+
"$schema" = "https://raw.githubusercontent.com/sourcebot-dev/sourcebot/main/schemas/v3/index.json";
177+
connections = {
178+
github-public = {
179+
type = "github";
180+
repos = [
181+
"sourcebot-dev/sourcebot"
182+
];
183+
};
184+
gitlab-private = {
185+
type = "gitlab";
186+
url = "https://gitlab.example.com";
187+
all = true;
188+
token = {
189+
env = "GITLAB_EXAMPLE_TOKEN";
190+
};
191+
exclude = {
192+
forks = true;
193+
};
194+
};
195+
};
196+
settings = {
197+
resyncConnectionIntervalMs = 1000 * 60 * 60 * 24 * 7; # 1 week
198+
reindexIntervalMs = 1000 * 60 * 60 * 24 * 7; # 1 week
199+
maxRepoIndexingJobConcurrency = 1000; # 8 default
200+
maxConnectionSyncJobConcurrency = 1000; # 8 default
201+
maxRepoGarbageCollectionJobConcurrency = 1000; # 8 default
202+
};
203+
})}";
204+
};
205+
```
206+
</Step>
207+
</Steps>
208+
209+
210+
98211
## Next steps
99212
---
100213

flake.lock

Lines changed: 133 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
description = "SourceBot - Code search and navigation tool";
3+
inputs = {
4+
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
5+
flake-utils.url = "github:numtide/flake-utils";
6+
microvm.url = "github:astro/microvm.nix";
7+
microvm.inputs.nixpkgs.follows = "nixpkgs";
8+
};
9+
outputs = {
10+
self,
11+
nixpkgs,
12+
flake-utils,
13+
microvm,
14+
}:
15+
flake-utils.lib.eachSystemPassThrough ["x86_64-linux"] (system: {
16+
nixosModules = rec {
17+
default = sourcebot;
18+
sourcebot = import ./nix/nixosModule.nix self;
19+
};
20+
21+
nixosConfigurations.testing = nixpkgs.lib.nixosSystem {
22+
inherit system;
23+
modules = [
24+
self.nixosModules.sourcebot
25+
];
26+
};
27+
28+
overlays.default = import ./nix/overlay.nix;
29+
})
30+
// flake-utils.lib.eachSystem ["x86_64-linux"] (
31+
system: let
32+
pkgs = import nixpkgs {
33+
inherit system;
34+
overlays = [self.overlays.default];
35+
};
36+
sourcebotSystem = nixpkgs.lib.nixosSystem {
37+
inherit system pkgs;
38+
modules = [
39+
microvm.nixosModules.microvm
40+
self.nixosModules.sourcebot
41+
./nix/microvm.nix
42+
];
43+
};
44+
in {
45+
packages = rec {
46+
default = sourcebot;
47+
sourcebot = pkgs.callPackage ./nix/sourcebot.nix {};
48+
microvm = sourcebotSystem.config.microvm.declaredRunner;
49+
};
50+
51+
checks.default = pkgs.callPackage ./nix/nixosTest.nix {inherit self;};
52+
53+
devShells.default = pkgs.mkShell {
54+
packages = with pkgs; [
55+
yarn-berry
56+
yarn-berry.yarn-berry-fetcher
57+
openssl
58+
yarn
59+
redis
60+
];
61+
buildInputs = with pkgs; [
62+
nodePackages.prisma
63+
];
64+
YARN_ENABLE_SCRIPTS = "false";
65+
PRISMA_SCHEMA_ENGINE_BINARY = "${pkgs.prisma-engines}/bin/schema-engine";
66+
PRISMA_QUERY_ENGINE_BINARY = "${pkgs.prisma-engines}/bin/query-engine";
67+
PRISMA_QUERY_ENGINE_LIBRARY = "${pkgs.prisma-engines}/lib/libquery_engine.node";
68+
PRISMA_FMT_BINARY = "${pkgs.prisma-engines}/bin/prisma-fmt";
69+
};
70+
}
71+
);
72+
}

0 commit comments

Comments
 (0)