Skip to content

Commit cd25f59

Browse files
Merge pull request #43 from angaz/nix_service
2 parents 2bdb487 + c9a85d7 commit cd25f59

File tree

4 files changed

+401
-44
lines changed

4 files changed

+401
-44
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ nodes
2121
node-crawler-backend.exe
2222
node-crawler-backend
2323
/data/
24+
25+
# nix
26+
result

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,125 @@ You can read the `./docker-compose.yml` file for more details.
146146
```
147147
docker-compose up
148148
```
149+
150+
## Developing with Nix
151+
152+
[Nix](https://nixos.org/) is a package manager and system configuration tool
153+
and language for reproducible, declarative, and reliable systems.
154+
155+
The Nix [Flake](https://nixos.wiki/wiki/Flakes) in this repo contains all the
156+
dependencies needed to build the frontend and crawler.
157+
158+
The `flake.lock` file locks the commit which the package manager uses to build
159+
the packages. Essentially locking the dependencies in time, not in version.
160+
161+
To update the lock file, use `nix flake update --commit-lock-file` this will
162+
update the git commits in the lock file, and commit the new lock file with a
163+
nice, standard commit message which shows the change in commit hashes for each
164+
input.
165+
166+
To activate the development environment with all the packages available, you
167+
can use the command `nix develop`. To automate this process, you can use
168+
[direnv](https://direnv.net/) with `use flake` in your `.envrc`. You can learn
169+
more about Nix and direnv [here](https://github.com/direnv/direnv/wiki/Nix).
170+
171+
## Deploying with NixOS
172+
173+
[Nix](https://nixos.org/) is a package manager and system configuration tool
174+
and language for reproducible, declarative, and reliable systems.
175+
176+
The Nix [Flake](https://nixos.wiki/wiki/Flakes) in this repo also contains a
177+
NixOS module for configuring and deploying the node-crawler, API, and Nginx.
178+
179+
There is just a little bit of extra configuration which is needed to bring
180+
everything together.
181+
182+
An example production configuration:
183+
184+
Your NixOS `flake.nix`:
185+
186+
```nix
187+
{
188+
inputs = {
189+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
190+
node-crawler.url = "github:ethereum/node-crawler";
191+
};
192+
outputs = {
193+
nixpkgs,
194+
node-crawler,
195+
}:
196+
{
197+
nixosConfigurations = {
198+
crawlerHostName = nixpkgs.lib.nixosSystem {
199+
specialArgs = {
200+
inherit node-crawler
201+
};
202+
modules = [
203+
./configuration.nix
204+
205+
node-crawler.nixosModules.nodeCrawler
206+
];
207+
};
208+
};
209+
};
210+
}
211+
```
212+
213+
Your example `configuration.nix`:
214+
215+
```nix
216+
{ node-crawler, ... }:
217+
218+
{
219+
# Add the overlay from the node-crawler flake
220+
# to get the added packages.
221+
nixpkgs.overlays = [
222+
node-crawler.overlays.default
223+
];
224+
225+
# It's a good idea to have your firewall
226+
# enabled. Make sure you have SSH allowed
227+
# so you don't lock yourself out. The openssh
228+
# service should do this by default.
229+
networking = {
230+
firewall = {
231+
enable = true;
232+
allowedTCPPorts = [
233+
80
234+
443
235+
];
236+
};
237+
};
238+
239+
services = {
240+
nodeCrawler = {
241+
enable = true;
242+
hostName = "server hostname";
243+
nginx = {
244+
forceSSL = true;
245+
enableACME = true;
246+
};
247+
};
248+
249+
# Needed for the node crawler to get the country
250+
# of the crawled IP address.
251+
geoipupdate = {
252+
enable = true;
253+
settings = {
254+
EditionIDs = [
255+
"GeoLite2-Country"
256+
];
257+
AccountID = account_id;
258+
LicenseKey = "location of licence key on server";
259+
};
260+
};
261+
};
262+
263+
# Needed to enable ACME for automatic SSL certificate
264+
# creation for Nginx.
265+
security.acme = {
266+
acceptTerms = true;
267+
defaults.email = "[email protected]";
268+
};
269+
}
270+
```

flake.lock

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

0 commit comments

Comments
 (0)