-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathflake.nix
More file actions
89 lines (86 loc) · 3.06 KB
/
flake.nix
File metadata and controls
89 lines (86 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:nixos/nixpkgs";
gomod2nix.url = "github:nix-community/gomod2nix";
devshell.url = "github:numtide/devshell";
};
outputs = inputs@{ self, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } ({ moduleWithSystem, ... }: {
imports = [ inputs.devshell.flakeModule ];
systems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ];
perSystem = { pkgs, system, config, ... }: {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ inputs.gomod2nix.overlays.default ];
};
packages.default = config.packages.indexer;
packages.vault-indexer = pkgs.buildGoApplication {
pname = "vault-indexer";
version = "latest";
src = ./.;
modules = ./gomod2nix.toml;
doCheck = false;
meta.mainProgram = "vault-indexer";
};
devshells.default = {
commands = [
{ package = pkgs.gomod2nix; }
{ package = pkgs.nixfmt-classic; }
{ package = pkgs.supabase-cli; }
];
};
};
flake.nixosModules.vault-indexer = moduleWithSystem ({ self' }:
{ lib, config, pkgs, ... }:
let
inherit (lib) types;
cfg = config.services.vault-indexer;
package = self'.packages.vault-indexer;
in {
options = {
services.vault-indexer = {
enable = lib.mkEnableOption "Vault Indexer";
};
};
config = lib.mkIf cfg.enable {
systemd.services.vault-indexer = {
description = "vault indexer";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
environment = { ENV = "prod"; };
path = with pkgs; [ supabase-cli ];
preStart = ''
mkdir -p github.com/timewave/
if [[ -d github.com/timewave/vault-indexer ]]; then
rm -rf github.com/timewave/vault-indexer
fi
ln -s ${package.src} github.com/timewave/vault-indexer
if [[ -d abis ]]; then
rm -rf abis
fi
ln -s ${package.src}/abis .
# Database Migration
source .env.prod
cd ${package.src}
supabase db push --db-url "$INDEXER_POSTGRES_CONNECTION_STRING"
cd -
'';
unitConfig = {
StartLimitBurst = 5;
StartLimitIntervalSec = "1m";
};
serviceConfig = {
ExecStart = "${lib.getExe package} prod";
Restart = "on-failure";
RestartSec = "1s";
RestartSteps = 40;
RestartMaxDelaySec = "20min";
StateDirectory = "vault-indexer";
WorkingDirectory = "/var/lib/vault-indexer";
};
};
};
});
});
}