-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
146 lines (145 loc) · 5.46 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
devenv.url = "github:cachix/devenv";
chainweb-node.url = "github:kadena-io/chainweb-node";
chainweb-node-l2.url = "github:kadena-io/chainweb-node/edmund/l2-spv-poc";
chainweb-data = {
url = "github:kadena-io/chainweb-data";
inputs.nixpkgs.follows = "chainweb-node/nixpkgs";
inputs.haskellNix.follows = "chainweb-node/haskellNix";
};
chainweb-mining-client = {
url = "github:kadena-io/chainweb-mining-client/enis/update-to-flakes-and-haskellNix";
inputs.haskellNix.follows = "chainweb-node/haskellNix";
inputs.nixpkgs.follows = "chainweb-node/nixpkgs";
};
pact = {
url = "github:kadena-io/pact";
inputs.haskellNix.follows = "chainweb-node/haskellNix";
inputs.nixpkgs.follows = "chainweb-node/nixpkgs";
};
block-explorer.url = "github:kadena-io/block-explorer/enis/devnet-support";
nix-exe-bundle = { url = "github:3noch/nix-bundle-exe"; flake = false; };
};
outputs = { self
, nixpkgs
, devenv
, ... } @ inputs:
inputs.flake-utils.lib.eachDefaultSystem (system: let
bundle = pkgs.callPackage inputs.nix-exe-bundle {};
get-flake-info = import lib/get-flake-info.nix inputs;
bundleWithInfo = inputs: let
get-flake-info = import lib/get-flake-info.nix inputs;
in flakeName: let
flakeInfo = get-flake-info flakeName;
default = inputs.${flakeName}.packages.${system}.default;
in bundle default // {
inherit flakeInfo;
version = default.version or default.meta.version or null;
};
bundleWithInfo' = bundleWithInfo inputs;
overlay = (self: super: {
chainweb-data = bundleWithInfo' "chainweb-data";
chainweb-mining-client = bundleWithInfo' "chainweb-mining-client";
chainweb-node = bundleWithInfo' "chainweb-node";
pact = bundleWithInfo' "pact";
block-explorer = inputs.block-explorer.packages.x86_64-linux.static // {
flakeInfo = get-flake-info "block-explorer";
};
});
chainweb-node-l2 = bundleWithInfo' "chainweb-node-l2";
pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; };
devnetInfo = {
devnetVersion = "0.1.0";
devnetRepo = "https://github.com/kadena-community/nix-kda-cli";
devnetRevision = self.rev or null;
};
modules = [
# https://devenv.sh/reference/options/
modules/chainweb-data.nix
modules/chainweb-node.nix
modules/chainweb-mining-client.nix
modules/http-server.nix
modules/ttyd.nix
modules/landing-page/module.nix
modules/pact-cli.nix
modules/process-compose.nix
modules/devnet-mode.nix
modules/explorer.nix
{ sites.landing-page = devnetInfo; }
];
packageExtras = {
};
containerExtras = with pkgs.lib; {config, ...}: {
devenv.root = "/devnet";
services.chainweb-data.extra-migrations-folder = "/cwd-extra-migrations";
sites.landing-page.container-api.enable = true;
imports = [
(mkIf config.services.postgres.enable {
processes.socat.exec = ''
${pkgs.socat}/bin/socat TCP-LISTEN:5432,reuseaddr,fork \
UNIX-CONNECT:${config.env.PGDATA}/.s.PGSQL.5432
'';
sites.landing-page.container-api.ports = mkAfter
"- `5432`: Postgresql";
})
];
sites.landing-page.container-api.folders = mkBefore "- `/data`: Persistent data folder";
};
mkFlake = cfgName: extraModule:
import ./mkDevnetFlake.nix {
inherit pkgs nixpkgs devenv containerExtras packageExtras;
containerTag = cfgName;
modules = modules ++ [
extraModule
{ sites.landing-page.devnetConfig = cfgName; }
];
};
configurations = let
minimal = {
services.chainweb-node.enable = true;
services.chainweb-mining-client.enable = true;
services.http-server.enable = true;
};
local = {
imports = [minimal];
services.chainweb-data.enable = true;
sites.explorer.enable = true;
};
container-common = {
imports = [local];
services.ttyd.enable = true;
services.pact-cli.enable = true;
};
use-cwn-l2 = {
services.chainweb-node.package = chainweb-node-l2;
};
# Useful for iterating on nginx configurations
http-only = {
services.http-server.enable = true;
# Keep process-compose alive even if nginx dies
processes.sleep.exec = "sleep 100";
sites.explorer.enable = true;
};
in {
default = local;
container-default = container-common;
l2 = { imports = [container-common use-cwn-l2]; };
minimal = minimal;
inherit http-only;
};
combined-flake = import lib/combine-flakes.nix pkgs.lib (
builtins.mapAttrs (cfgName: config: mkFlake cfgName config) configurations
);
in pkgs.lib.recursiveUpdate combined-flake {
apps.develop-page = {
type = "app";
program = (import ./lib/develop-page.nix {inherit pkgs;}).outPath;
};
inherit configurations;
overlays.default = overlay;
lib = { inherit mkFlake bundleWithInfo; };
});
}