This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
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
156 additions
and
6 deletions.
There are no files selected for viewing
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,53 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
let | ||
cfg = config.services.smash; | ||
in { | ||
|
||
options = { | ||
services.smash = { | ||
enable = lib.mkEnableOption "enable the smash server"; | ||
script = lib.mkOption { | ||
internal = true; | ||
type = lib.types.package; | ||
}; | ||
package = lib.mkOption { | ||
type = lib.types.package; | ||
default = (import ../. {}).smashHaskellPackages.smash.components.exes.smash-exe; | ||
}; | ||
}; | ||
}; | ||
config = lib.mkIf cfg.enable { | ||
services.smash.script = pkgs.writeShellScript "smash" '' | ||
set -euo pipefail | ||
cp ${config.services.cardano-db-sync.pgpass} $RUNTIME_DIRECTORY/pgpass | ||
chmod 0600 $RUNTIME_DIRECTORY/pgpass | ||
export PGPASSFILE=$RUNTIME_DIRECTORY/pgpass | ||
${cfg.package}/bin/smash-exe run-migrations --mdir ${../../schema} | ||
exec ${cfg.package}/bin/smash-exe run-app | ||
''; | ||
environment.systemPackages = [ cfg.package config.services.postgresql.package ]; | ||
systemd.services.smash = { | ||
path = [ cfg.package config.services.postgresql.package pkgs.netcat ]; | ||
preStart = '' | ||
for x in {1..10}; do | ||
nc -z localhost ${toString config.services.cardano-db-sync.postgres.port} && break | ||
echo loop $x: waiting for postgresql 2 sec... | ||
sleep 2 | ||
done | ||
sleep 1 | ||
''; | ||
serviceConfig = { | ||
ExecStart = config.services.smash.script; | ||
DynamicUser = true; | ||
RuntimeDirectory = "smash"; | ||
}; | ||
|
||
wantedBy = [ "multi-user.target" ]; | ||
after = [ "postgres.service" "cardano-db-sync.service" ]; | ||
requires = [ "postgresql.service" ]; | ||
}; | ||
}; | ||
} |
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,20 @@ | ||
{ pkgs | ||
, supportedSystems ? [ "x86_64-linux" ] | ||
}: | ||
|
||
with pkgs; | ||
with pkgs.commonLib; | ||
|
||
let | ||
forAllSystems = genAttrs supportedSystems; | ||
importTest = fn: args: system: let | ||
imported = import fn; | ||
test = import (pkgs.path + "/nixos/tests/make-test.nix") imported; | ||
in test ({ | ||
inherit pkgs system config; | ||
} // args); | ||
callTest = fn: args: forAllSystems (system: hydraJob (importTest fn args system)); | ||
in rec { | ||
|
||
smashTest = callTest ./smash-test.nix {}; | ||
} |
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,61 @@ | ||
{ pkgs, ... }: | ||
with pkgs; with commonLib; | ||
{ | ||
name = "smash-test"; | ||
nodes = { | ||
machine = { config, ... }: { | ||
nixpkgs.pkgs = pkgs; | ||
environment = { | ||
systemPackages = with pkgs; [ curl jq ]; | ||
variables = { | ||
PGPASSFILE = config.services.cardano-db-sync.pgpass; | ||
}; | ||
}; | ||
imports = [ | ||
../smash-service.nix | ||
(sources.cardano-db-sync + "/nix/nixos") | ||
]; | ||
services.cardano-db-sync = { | ||
enable = true; | ||
cluster = "ff"; | ||
}; | ||
services.smash = { | ||
enable = true; | ||
package = smashHaskellPackages.smash.components.exes.smash-exe; | ||
}; | ||
services.postgresql = { | ||
enable = true; | ||
package = postgresql_12; | ||
enableTCPIP = false; | ||
ensureDatabases = [ "${config.services.cardano-db-sync.user}" ]; | ||
ensureUsers = [ | ||
{ | ||
name = "${config.services.cardano-db-sync.user}"; | ||
ensurePermissions = { | ||
"DATABASE ${config.services.cardano-db-sync.user}" = "ALL PRIVILEGES"; | ||
}; | ||
} | ||
]; | ||
identMap = '' | ||
cdbsync-users root ${config.services.cardano-db-sync.user} | ||
cdbsync-users smash ${config.services.cardano-db-sync.user} | ||
cdbsync-users ${config.services.cardano-db-sync.user} ${config.services.cardano-db-sync.user} | ||
cdbsync-users postgres postgres | ||
''; | ||
authentication = '' | ||
local all all ident map=cdbsync-users | ||
''; | ||
}; | ||
}; | ||
}; | ||
testScript = '' | ||
startAll | ||
$machine->waitForUnit("postgresql.service"); | ||
$machine->waitForUnit("smash.service"); | ||
$machine->waitForOpenPort(3100); | ||
$machine->succeed("smash-exe insert-pool --filepath ${../../../test_pool.json} --poolhash \"cbdfc4f21feb0a414b2b9471fa56b0ebd312825e63db776d68cc3fa0ca1f5a2f\""); | ||
$machine->succeed("curl -s -i -H \"Accept: application/json\" http://localhost:3100/api/v1/metadata/cbdfc4f21feb0a414b2b9471fa56b0ebd312825e63db776d68cc3fa0ca1f5a2f | systemd-cat --identifier=curl-smash"); | ||
$machine->succeed("curl -s -H \"Accept: application/json\" http://localhost:3100/api/v1/metadata/cbdfc4f21feb0a414b2b9471fa56b0ebd312825e63db776d68cc3fa0ca1f5a2f | jq | systemd-cat --identifier=jq-smash"); | ||
''; | ||
|
||
} |
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