-
Notifications
You must be signed in to change notification settings - Fork 161
/
flake.nix
138 lines (117 loc) · 4.32 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
{
description = "cardano-db-sync";
inputs = {
nixpkgs.follows = "haskellNix/nixpkgs-unstable";
hackageNix = {
url = "github:input-output-hk/hackage.nix";
flake = false;
};
nixTools = {
url = "github:input-output-hk/nix-tools";
flake = false;
};
haskellNix.url = "github:input-output-hk/haskell.nix";
utils.url = "github:numtide/flake-utils";
iohkNix = {
url = "github:input-output-hk/iohk-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
customConfig = { url = "path:./custom-config"; };
};
outputs = { self, iohkNix, haskellNix, nixpkgs, utils, customConfig, ... }:
let
inherit (haskellNix) config;
inherit (nixpkgs) lib;
inherit (lib)
systems mapAttrs recursiveUpdate mkDefault optionalAttrs nameValuePair
attrNames getAttrs head;
inherit (utils.lib) eachSystem mkApp flattenTree;
inherit (iohkNix.lib) prefixNamesWith collectExes;
supportedSystems = import ./supported-systems.nix;
defaultSystem = head supportedSystems;
overlays = [
haskellNix.overlay
iohkNix.overlays.haskell-nix-extra
iohkNix.overlays.crypto
iohkNix.overlays.cardano-lib
iohkNix.overlays.utils
(final: prev: {
customConfig =
recursiveUpdate (import ./custom-config final.customConfig)
customConfig.outputs;
gitrev = self.rev or "dirty";
commonLib = lib // iohkNix.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.cardanoDbSyncProject.flake { };
muslFlake = (import nixpkgs {
inherit system overlays config;
crossSystem = systems.examples.musl64;
}).cardanoDbSyncProject.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.cardanoDbSyncProject.projectModule) src;
};
stylish-haskell = pkgs.callPackage pkgs.stylishHaskellCheck {
inherit (pkgs.cardanoDbSyncProject.projectModule) src;
};
};
exes = collectExes flake.packages;
exeNames = attrNames exes;
lazyCollectExe = p: getAttrs exeNames (collectExes p);
packages = {
inherit (devShell) devops;
inherit (pkgs) cardano-db-sync cardano-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."cardano-db-sync:exe:cardano-db-sync";
# Run by `nix run .`
defaultApp = flake.apps."cardano-db-sync:exe:cardano-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
'';
};
cardano-node = {
type = "app";
program = pkgs.cardano-node.exePath;
};
} # nix run .#<exe>
// (collectExes flake.apps);
}) // {
overlay = final: prev:
with self.legacyPackages.${final.system}; {
inherit cardano-db-sync cardano-node dockerImage;
};
nixosModules = {
cardano-db-sync = { pkgs, lib, ... }: {
imports = [ ./nix/nixos/cardano-db-sync-service.nix ];
services.cardano-db-sync.dbSyncPkgs =
lib.mkDefault self.legacyPackages.${pkgs.system};
};
};
};
}