-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflake.nix
148 lines (136 loc) · 5.35 KB
/
flake.nix
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# This flake was initially generated by fh, the CLI for FlakeHub (version 0.1.10)
{
# Flake inputs
inputs = {
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/*.tar.gz";
flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/*.tar.gz";
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*.tar.gz";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
# Flake outputs that other flakes can use
outputs = { self, flake-compat, flake-schemas, nixpkgs, rust-overlay }:
let
# Nixpkgs overlays
overlays = [
rust-overlay.overlays.default
(final: prev: {
rustToolchain = final.rust-bin.stable.latest.default;
})
];
# Helpers for producing system-specific outputs
supportedSystems = [ "x86_64-linux" "aarch64-darwin" "x86_64-darwin" "aarch64-linux" ];
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
pkgs = import nixpkgs { inherit overlays system; };
});
in {
# Schemas tell Nix about the structure of your flake's outputs
schemas = flake-schemas.schemas;
# The package
packages = forEachSupportedSystem ({ pkgs }: rec {
default = umbrella;
umbrella =
((let rustVersion = pkgs.rust-bin.stable.latest.default;
in pkgs.makeRustPlatform {
cargo = rustVersion;
rustc = rustVersion;
}).buildRustPackage {
pname = "umbrella";
version = "0.1.0";
src = ./.;
cargoSha256 = "";
cargoLock.lockFile = ./Cargo.lock;
cargoLock.outputHashes = {
"decaf377-fmd-0.79.0-alpha.1" = "sha256-sLN6SmM4QyewLLqQhHL3UKV9TuAT1NbtAPkq0/50cLQ=";
"f4jumble-0.0.0" = "sha256-Zc07fVIPuGVq6gUW1OOehr7HkcCBNUPYNh7POmRECrE=";
};
}).overrideAttrs (_: { doCheck = false; }); # Disable tests to improve build times
});
# The module
nixosModules = rec {
default = umbrella;
umbrella = { config, lib, pkgs, ... }:
let
cfg = config.services.umbrella;
umbrella = self.outputs.packages.${pkgs.system}.default;
in {
options = {
services.umbrella = with lib; with types; {
enable = mkEnableOption "Enable Umbrella service to monitor Penumbra validator nodes";
nodes = mkOption {
type = listOf str;
description = "List of fullnodes to connect to";
default = [];
};
fallbacks = mkOption {
type = listOf str;
description = "List of fallback RPC endpoints to connect to";
default = [];
};
validators = mkOption {
type = listOf str;
description = "List of validator identity keys to monitor";
default = [];
};
bind = mkOption {
type = nullOr str;
description = "Address to bind the /metrics endpoint to, default if unspecified";
default = null;
};
poll = mkOption {
type = nullOr str;
description = "Minimum interval at which the exporter polls the RPC endpoints, default if unspecified";
default = null;
};
timeout = mkOption {
type = nullOr str;
description = "Timeout for connecting to the RPC endpoints, default if unspecified";
default = null;
};
};
};
config = with lib; mkIf config.services.umbrella.enable {
environment.systemPackages = [ umbrella ];
systemd.services.umbrella = {
description = "Umbrella service to monitor Penumbra validator nodes";
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = ''
${umbrella}/bin/umbrella \
${concatStringsSep " " (map (n: "--node ${n}") cfg.nodes)} \
${concatStringsSep " " (map (f: "--fallback ${f}") cfg.fallbacks)} \
${concatStringsSep " " (map (v: "--validator ${v}") cfg.validators)} \
${optionalString (cfg.bind != null) (b: "--bind ${b}")} \
${optionalString (cfg.poll != null) (p: "--poll-interval ${p}")} \
${optionalString (cfg.timeout != null) (c: "--connect-timeout ${c}")}
'';
Restart = "always";
DynamicUser = "yes";
RestartSec = "5";
};
};
};
};
};
# Development environments
devShells = forEachSupportedSystem ({ pkgs }: {
default = pkgs.mkShell {
# Pinned packages available in the environment
packages = with pkgs; [
rustToolchain
cargo-bloat
cargo-edit
cargo-outdated
cargo-udeps
cargo-watch
];
# Environment variables
env = {
RUST_BACKTRACE = "1";
};
};
});
};
}