Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
221 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
{ | ||
description = "Cardano DB Sync"; | ||
|
||
inputs = { | ||
haskell-nix.url = "github:input-output-hk/haskell.nix"; | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-20.09"; | ||
utils.url = "github:numtide/flake-utils"; | ||
}; | ||
|
||
outputs = { self, nixpkgs, utils, haskell-nix, ... }: | ||
(utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" ] (system: | ||
let | ||
legacyPackages = import ./nix { | ||
inherit system; | ||
ownHaskellNix = haskell-nix.legacyPackages.${system}; | ||
gitrev = self.rev or "dirty"; | ||
}; | ||
|
||
lib = nixpkgs.lib; | ||
sources = import ./nix/sources.nix { }; | ||
iohkNix = import sources.iohk-nix { inherit system; }; | ||
environments = iohkNix.cardanoLib.environments; | ||
environmentName = "testnet"; | ||
|
||
eachEnv = lib.flip lib.pipe [ | ||
(lib.forEach (builtins.attrNames environments)) | ||
lib.listToAttrs | ||
]; | ||
|
||
config = env: | ||
{ pkgs, ... }: { | ||
services.cardano-db-sync = rec { | ||
enable = true; | ||
cluster = env; | ||
environment = environments.${env}; | ||
logConfig = iohkNix.cardanoLib.defaultExplorerLogConfig; | ||
stateDir = "/persist"; | ||
extended = true; | ||
package = pkgs.cardano-db-sync-extended; | ||
postgres.generatePGPASS = false; | ||
}; | ||
|
||
services.postgresql = { enable = true; }; | ||
}; | ||
|
||
evaluated = env: | ||
lib.nixosSystem { | ||
inherit system; | ||
pkgs = legacyPackages; | ||
modules = [ ./nix/nixos/cardano-db-sync-service.nix (config env) ]; | ||
}; | ||
|
||
packages = (eachEnv (env: | ||
lib.nameValuePair "cardano-db-sync-extended-${env}" (let | ||
vanilla = | ||
legacyPackages.runCommand "cardano-db-sync-extended-entrypoint" | ||
{ } '' | ||
install -Dm0777 ${ | ||
(evaluated env).config.services.cardano-db-sync.script | ||
} $out/bin/cardano-db-sync-extended-entrypoint | ||
''; | ||
deps = with legacyPackages; [ | ||
coreutils | ||
findutils | ||
gnugrep | ||
gnused | ||
postgresql | ||
strace | ||
lsof | ||
dnsutils | ||
bashInteractive | ||
iproute | ||
curl | ||
netcat | ||
bat | ||
tree | ||
]; | ||
|
||
closure = legacyPackages.symlinkJoin { | ||
name = "cardano-db-sync-extended-entrypoint"; | ||
paths = [ vanilla ] ++ deps; | ||
}; | ||
in closure))) // { | ||
postgres = let | ||
deps = with legacyPackages; [ | ||
coreutils | ||
findutils | ||
gnugrep | ||
gnused | ||
postgresql | ||
strace | ||
bashInteractive | ||
]; | ||
|
||
configs = rec { | ||
hba = legacyPackages.writeText "pg_hba.conf" '' | ||
# Generated file; do not edit! | ||
local all all peer | ||
host all all 127.0.0.1/32 md5 | ||
host all all ::1/128 md5 | ||
''; | ||
ident = legacyPackages.writeText "pg_ident.conf" ""; | ||
postgres = legacyPackages.writeText "postgresql.conf" '' | ||
hba_file = '${hba}' | ||
ident_file = '${ident}' | ||
listen_addresses = '0.0.0.0' | ||
log_destination = 'stderr' | ||
log_line_prefix = '[%p] ' | ||
port = 5432 | ||
''; | ||
}; | ||
|
||
PATH = lib.makeBinPath deps; | ||
|
||
entrypoint = | ||
legacyPackages.writeShellScriptBin "postgres-entrypoint" '' | ||
set -exuo pipefail | ||
export PATH="${PATH}" | ||
export LOCALE_ARCHIVE=${legacyPackages.glibcLocales}/lib/locale/locale-archive | ||
mkdir -p /run/postgresql | ||
mkdir -p "$PGDATA" | ||
chmod 0700 "$PGDATA" | ||
if [ ! -s "$PGDATA/PG_VERSION" ]; then | ||
initdb | ||
fi | ||
ln -sfn "${configs.postgres}" "$PGDATA/postgresql.conf" | ||
exec postgres "$@" | ||
''; | ||
in legacyPackages.symlinkJoin { | ||
name = "postgres-entrypoint"; | ||
paths = [ entrypoint ] ++ deps; | ||
}; | ||
}; | ||
in { | ||
inherit environments evaluated legacyPackages packages; | ||
|
||
apps = (eachEnv (env: | ||
lib.nameValuePair "cardano-db-sync-extended-${env}" (utils.lib.mkApp { | ||
drv = packages."cardano-db-sync-extended-${env}"; | ||
exePath = "/bin/cardano-db-sync-extended-entrypoint"; | ||
}))) // { | ||
postgres = utils.lib.mkApp { | ||
drv = packages.postgres; | ||
exePath = "/bin/postgres"; | ||
}; | ||
}; | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
builtins.getFlake (toString ./.) |