forked from The-Blockchain-Company/bcc-db-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
131 lines (110 loc) · 4.09 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
{
description = "bcc-db-sync";
inputs = {
haskellNix.url = "github:The-Blockchain-Company/haskell.nix";
tbcoNix = {
url = "github:The-Blockchain-Company/tbco-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs.follows = "haskellNix/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
customConfig = {
url = "path:./custom-config";
};
};
outputs = { self, tbcoNix, haskellNix, nixpkgs, utils, customConfig, ... }:
let
inherit (haskellNix.internal) config;
inherit (nixpkgs) lib;
inherit (lib) systems mapAttrs recursiveUpdate mkDefault optionalAttrs nameValuePair
attrNames getAttrs head;
inherit (utils.lib) eachSystem mkApp flattenTree;
inherit (tbcoNix.lib) prefixNamesWith collectExes;
supportedSystems = import ./supported-systems.nix;
defaultSystem = head supportedSystems;
overlays = [
haskellNix.overlay
tbcoNix.overlays.haskell-nix-extra
tbcoNix.overlays.crypto
tbcoNix.overlays.bcc-lib
tbcoNix.overlays.utils
(final: prev: {
customConfig = recursiveUpdate
(import ./custom-config final.customConfig)
customConfig.outputs;
gitrev = self.rev or "dirty";
commonLib = lib
// tbcoNix.lib;
})
(import ./nix/pkgs.nix)
];
in eachSystem supportedSystems (system:
let
pkgs = import nixpkgs { inherit system overlays config; };
devShell = import ./shell.nix { inherit pkgs; };
flake = pkgs.bccDbSyncProject.flake {};
muslFlake = (import nixpkgs { inherit system overlays config;
crossSystem = systems.examples.musl64;
}).bccDbSyncProject.flake {};
scripts = flattenTree pkgs.scripts;
checkNames = attrNames flake.checks;
checks =
# checks run on default system only;
optionalAttrs (system == defaultSystem) {
hlint = pkgs.callPackage pkgs.hlintCheck {
inherit (pkgs.bccDbSyncProject.projectModule) src;
};
stylish-haskell = pkgs.callPackage pkgs.stylishHaskellCheck {
inherit (pkgs.bccDbSyncProject.projectModule) src;
};
};
exes = collectExes flake.packages;
exeNames = attrNames exes;
lazyCollectExe = p: getAttrs exeNames (collectExes p);
packages = {
inherit (devShell) devops;
inherit (pkgs) bcc-db-sync bcc-db-sync-extended bcc-node
dockerImage;
}
// exes
// (prefixNamesWith "static/"
(mapAttrs pkgs.rewriteStatic (lazyCollectExe
(if system == "x86_64-darwin" then flake else muslFlake).packages)))
// scripts
# Add checks to be able to build them individually
// (prefixNamesWith "checks/" checks);
in recursiveUpdate flake {
inherit packages checks;
legacyPackages = pkgs;
# Built by `nix build .`
defaultPackage = flake.packages."bcc-db-sync:exe:bcc-db-sync";
# Run by `nix run .`
defaultApp = flake.apps."bcc-db-sync:exe:bcc-db-sync";
# 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-node = { type = "app"; program = pkgs.bcc-node.exePath; };
} # nix run .#<exe>
// (collectExes flake.apps);
}
) // {
overlay = final: prev: with self.legacyPackages.${final.system}; {
inherit bcc-db-sync bcc-db-sync-extended bcc-node
dockerImage;
};
nixosModules = {
bcc-db-sync = { pkgs, lib, ... }: {
imports = [ ./nix/nixos/bcc-db-sync-service.nix ];
services.bcc-db-sync.dbSyncPkgs = lib.mkDefault self.legacyPackages.${pkgs.system};
};
};
};
}