Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Commit

Permalink
make nix scripts work correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
disassembler committed Sep 16, 2019
1 parent 579ec82 commit fd4128c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ dist-newstyle/
.stack-work/
dist
*.swp
log-dir
result*
launch_*
21 changes: 3 additions & 18 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,6 @@ let
inherit (iohkLib.nix-tools) iohk-extras iohk-module;
};

mkConnectScript = { genesisFile, genesisHash, name, ... }:
let
extraModule = {
services.cardano-exporter = {
enable = true;
inherit genesisFile genesisHash;
cluster = name;
};
};
eval = pkgs.lib.evalModules {
prefix = [];
check = false;
modules = [ ./module.nix extraModule customConfig ];
args = { inherit pkgs; };
};
in eval.config.services.cardano-exporter.script;

in {
inherit pkgs iohkLib src haskellPackages;
inherit (haskellPackages.cardano-explorer.identifier) version;
Expand All @@ -62,7 +45,9 @@ in {
tests = util.collectComponents "tests" util.isIohkSkeleton haskellPackages;
benchmarks = util.collectComponents "benchmarks" util.isIohkSkeleton haskellPackages;

scripts.exporter = iohkLib.cardanoLib.forEnvironments mkConnectScript;
scripts = pkgs.callPackage ./nix/scripts.nix {
inherit iohkLib customConfig;
};

# This provides a development environment that can be used with nix-shell or
# lorri. See https://input-output-hk.github.io/haskell.nix/user-guide/development/
Expand Down
26 changes: 14 additions & 12 deletions module.nix → nix/nixos/cardano-exporter-service.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ lib, pkgs, config, ... }:

let
self = import ./. { };
self = import ../.. { };
cfg = config.services.cardano-exporter;
socketdir = "/var/run/postgresql";
port = 5432;
Expand All @@ -15,9 +15,6 @@ in {
internal = true;
type = lib.types.package;
};
genesisFile = lib.mkOption {
type = lib.types.path;
};
genesisHash = lib.mkOption {
type = lib.types.str;
};
Expand All @@ -30,7 +27,8 @@ in {
default = null;
};
socketPath = lib.mkOption {
type = lib.types.path;
type = lib.types.nullOr lib.types.path;
default = null;
};
};
};
Expand Down Expand Up @@ -88,24 +86,28 @@ in {
script = pkgs.writeScript "cardano-exporter-${cfg.cluster}" ''
#!${pkgs.stdenv.shell}
${if (cfg.socketPath == null) then ''if [ -z "$CARDANO_NODE_SOCKET_PATH" ]
then
echo "You must set \$CARDANO_NODE_SOCKET_PATH"
exit 1
fi'' else "export CARDANO_NODE_SOCKET_PATH=${cfg.socketPath}"}
export PATH=${lib.makeBinPath [ self.cardano-explorer-node self.haskellPackages.cardano-explorer-db.components.exes.cardano-explorer-db-manage pkgs.postgresql ]}:$PATH
export PGPASSFILE=${pgpass}
mkdir log-dir
cardano-explorer-db-manage run-migrations --mdir ${./schema} --ldir log-dir
mkdir -p log-dir
exec cardano-explorer-node --log-config ${./log-configuration.yaml} \
--genesis-file ${cfg.genesisFile} \
exec cardano-explorer-node --log-config ${../../log-configuration.yaml} \
--genesis-hash ${cfg.genesisHash} \
--socket-path ${cfg.socketPath}
--socket-path $CARDANO_NODE_SOCKET_PATH \
--schema-dir ${../../schema}
'';
};
})
(lib.mkIf (cfg.environment != null) {
services.cardano-exporter = {
inherit (cfg.environment) genesisFile genesisHash;
inherit (cfg.environment) genesisHash;
};
})
];
Expand Down
28 changes: 28 additions & 0 deletions nix/scripts.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ iohkLib, customConfig }:
with iohkLib.pkgs.lib;
let
pkgs = iohkLib.pkgs;
mkConnectScript = envConfig: let
extraModule = {
services.cardano-exporter = {
enable = true;
inherit (envConfig) genesisHash;
cluster = envConfig.name;
};
};
systemdCompat.options = {
systemd.services = mkOption {};
services.postgresql = mkOption {};
users = mkOption {};
};
eval = pkgs.lib.evalModules {
prefix = [];
modules = [ ./nixos/cardano-exporter-service.nix systemdCompat extraModule customConfig ];
args = { inherit pkgs; };
};
in eval.config.services.cardano-exporter.script;

scripts = iohkLib.cardanoLib.forEnvironments (environment: {
exporter = mkConnectScript environment;
});
in scripts

0 comments on commit fd4128c

Please sign in to comment.