Skip to content

Commit 8408caa

Browse files
committed
flake.nix
Package Sourcebot with Nix, NixOS module for deployment, integration test and microvm.
1 parent 5dcc538 commit 8408caa

File tree

9 files changed

+1000
-0
lines changed

9 files changed

+1000
-0
lines changed

docs/docs/deployment-guide.mdx

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

@@ -72,6 +74,117 @@ The following guide will walk you through the steps to deploy Sourcebot on your
7274
</Step>
7375
</Steps>
7476

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

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: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
bun
75+
redis
76+
jq
77+
];
78+
buildInputs = with pkgs; [
79+
nodePackages.prisma
80+
];
81+
YARN_ENABLE_SCRIPTS = "false";
82+
PRISMA_SCHEMA_ENGINE_BINARY = "${pkgs.prisma-engines}/bin/schema-engine";
83+
PRISMA_QUERY_ENGINE_BINARY = "${pkgs.prisma-engines}/bin/query-engine";
84+
PRISMA_QUERY_ENGINE_LIBRARY = "${pkgs.prisma-engines}/lib/libquery_engine.node";
85+
PRISMA_FMT_BINARY = "${pkgs.prisma-engines}/bin/prisma-fmt";
86+
};
87+
}
88+
);
89+
}

0 commit comments

Comments
 (0)