Skip to content

Commit 3b20128

Browse files
committed
flake.nix
Package Sourcebot with Nix, NixOS module for deployment, integration test and microvm.
1 parent 77593a9 commit 3b20128

File tree

9 files changed

+992
-0
lines changed

9 files changed

+992
-0
lines changed

docs/docs/deployment-guide.mdx

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,28 @@ 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

12+
### Walkthrough video
13+
---
14+
15+
Watch this 1:51 minute video to get a quick overview of how to deploy Sourcebot using Docker.
16+
17+
<iframe
18+
src="https://www.youtube.com/embed/1_JCr05haWc"
19+
title="YouTube video player"
20+
frameborder="0"
21+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
22+
allowfullscreen
23+
className="aspect-video w-full"
24+
></iframe>
25+
26+
### Step-by-step guide
27+
---
28+
1029
<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>
1130

1231
<Steps>
@@ -72,6 +91,117 @@ The following guide will walk you through the steps to deploy Sourcebot on your
7291
</Step>
7392
</Steps>
7493

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

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: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
({
25+
pkgs,
26+
lib,
27+
...
28+
}: {
29+
imports = [
30+
self.nixosModules.sourcebot
31+
];
32+
system.stateVersion = "25.05";
33+
boot.isContainer = true; # stop nix flake check complaining about missing root fs
34+
documentation.nixos.enable = false; # skip generating nixos docs
35+
virtualisation.vmVariant = {
36+
boot.isContainer = lib.mkForce false; # let vm variant create a virtual disk
37+
virtualisation.graphics = false; # connect serial console to terminal
38+
};
39+
})
40+
];
41+
};
42+
43+
overlays.default = import ./nix/overlay.nix;
44+
})
45+
// flake-utils.lib.eachSystem ["x86_64-linux"] (
46+
system: let
47+
pkgs = import nixpkgs {
48+
inherit system;
49+
overlays = [self.overlays.default];
50+
};
51+
sourcebotSystem = nixpkgs.lib.nixosSystem {
52+
inherit system pkgs;
53+
modules = [
54+
microvm.nixosModules.microvm
55+
self.nixosModules.sourcebot
56+
./nix/microvm.nix
57+
];
58+
};
59+
in {
60+
packages = rec {
61+
default = sourcebot;
62+
sourcebot = pkgs.callPackage ./nix/sourcebot.nix {};
63+
microvm = sourcebotSystem.config.microvm.declaredRunner;
64+
};
65+
66+
checks.default = pkgs.callPackage ./nix/nixosTest.nix {inherit self;};
67+
68+
devShells.default = pkgs.mkShell {
69+
packages = with pkgs; [
70+
yarn-berry
71+
yarn-berry.yarn-berry-fetcher
72+
openssl
73+
yarn
74+
redis
75+
];
76+
buildInputs = with pkgs; [
77+
nodePackages.prisma
78+
];
79+
YARN_ENABLE_SCRIPTS = "false";
80+
PRISMA_SCHEMA_ENGINE_BINARY = "${pkgs.prisma-engines}/bin/schema-engine";
81+
PRISMA_QUERY_ENGINE_BINARY = "${pkgs.prisma-engines}/bin/query-engine";
82+
PRISMA_QUERY_ENGINE_LIBRARY = "${pkgs.prisma-engines}/lib/libquery_engine.node";
83+
PRISMA_FMT_BINARY = "${pkgs.prisma-engines}/bin/prisma-fmt";
84+
};
85+
}
86+
);
87+
}

0 commit comments

Comments
 (0)