-
Notifications
You must be signed in to change notification settings - Fork 2
/
flake.nix
154 lines (132 loc) · 5.11 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
149
150
151
152
153
154
{
description = "Bcc Node";
inputs = {
# IMPORTANT: report any change to nixpkgs channel in nix/default.nix:
nixpkgs.follows = "haskellNix/nixpkgs-2105";
haskellNix = {
url = "github:The-Blockchain-Company/haskell.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
utils.url = "github:rmourey26/flake-utils";
tbcoNix = {
url = "github:The-Blockchain-Company/tbco-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
# Custom user config (default: empty), eg.:
# { outputs = {...}: {
# # Cutomize listeming port of node scripts:
# nixosModules.bcc-node = {
# services.bcc-node.port = 3002;
# };
# };
customConfig.url = "github:The-Blockchain-Company/empty-flake";
};
outputs = { self, nixpkgs, utils, haskellNix, tbcoNix, customConfig }:
let
inherit (nixpkgs) lib;
inherit (lib) head systems mapAttrs recursiveUpdate mkDefault
getAttrs optionalAttrs nameValuePair attrNames;
inherit (utils.lib) eachSystem mkApp flattenTree;
inherit (tbcoNix.lib) prefixNamesWith collectExes;
supportedSystems = import ./supported-systems.nix;
defaultSystem = head supportedSystems;
overlays = [
tbcoNix.overlays.haskell-nix-extra
tbcoNix.overlays.crypto
tbcoNix.overlays.bcc-lib
tbcoNix.overlays.utils
(final: prev: {
customConfig = recursiveUpdate
(import ./nix/custom-config.nix final.customConfig)
customConfig.outputs;
gitrev = self.rev or "dirty";
commonLib = lib
// tbcoNix.lib
// final.bccLib
// import ./nix/svclib.nix { inherit (final) pkgs; };
})
(import ./nix/pkgs.nix)
];
in eachSystem supportedSystems (system:
let
pkgs = haskellNix.legacyPackages.${system}.appendOverlays overlays;
inherit (pkgs.commonLib) eachEnv environments;
devShell = import ./shell.nix { inherit pkgs; };
flake = pkgs.bccNodeProject.flake {};
staticFlake = pkgs.pkgsStatic.bccNodeProject.flake {};
windowsFlake = pkgs.pkgsCross.${systems.examples.mingwW64}.bccNodeProject.flake {};
scripts = flattenTree pkgs.scripts;
checkNames = attrNames flake.checks;
checks =
# Linux only checks:
optionalAttrs (system == "x86_64-linux") (
prefixNamesWith "windows/" (removeAttrs
(getAttrs checkNames windowsFlake.checks)
["bcc-node-chairman:test:chairman-tests"]
)
// (prefixNamesWith "nixosTests/" (mapAttrs (_: v: v.${system} or v) pkgs.nixosTests))
)
# checks run on default system only;
// optionalAttrs (system == defaultSystem) {
hlint = pkgs.callPackage pkgs.hlintCheck {
inherit (pkgs.bccNodeProject.projectModule) src;
};
};
exes = collectExes flake.packages;
exeNames = attrNames exes;
lazyCollectExe = p: getAttrs exeNames (collectExes p);
packages = {
inherit (devShell) devops;
inherit (pkgs) bcc-node-profiled bcc-node-eventlogged bcc-node-asserted tx-generator-profiled locli-profiled;
}
// scripts
// exes
// (prefixNamesWith "static/"
(mapAttrs pkgs.rewriteStatic (lazyCollectExe staticFlake.packages)))
# Linux only packages:
// optionalAttrs (system == "x86_64-linux") (
prefixNamesWith "windows/" (lazyCollectExe windowsFlake.packages)
// {
"dockerImage/node" = pkgs.dockerImage;
"dockerImage/submit-api" = pkgs.submitApiDockerImage;
}
)
# Add checks to be able to build them individually
// (prefixNamesWith "checks/" checks);
in recursiveUpdate flake {
inherit environments packages checks;
legacyPackages = pkgs;
# Built by `nix build .`
defaultPackage = flake.packages."bcc-node:exe:bcc-node";
# Run by `nix run .`
defaultApp = flake.apps."bcc-node:exe:bcc-node";
# This is used by `nix develop .` to open a devShell
inherit devShell;
apps = {
repl = mkApp {
drv = pkgs.writeShellScriptBin "repl" ''
confnix=$(mktemp)
echo "builtins.getFlake (toString $(git rev-parse --show-toplevel))" >$confnix
trap "rm $confnix" EXIT
nix repl $confnix
'';
};
bcc-ping = { type = "app"; program = pkgs.bcc-ping.exePath; };
}
# nix run .#<exe>
// (collectExes flake.apps);
}
) // {
overlay = import ./overlay.nix self;
nixosModules = {
bcc-node = { pkgs, lib, ... }: {
imports = [ ./nix/nixos/bcc-node-service.nix ];
services.bcc-node.bccNodePkgs = lib.mkDefault self.legacyPackages.${pkgs.system};
};
bcc-submit-api = { pkgs, lib, ... }: {
imports = [ ./nix/nixos/bcc-submit-api-service.nix ];
services.bcc-submit-api.bccNodePkgs = lib.mkDefault self.legacyPackages.${pkgs.system};
};
};
};
}