Skip to content

Commit

Permalink
remove mostly redondant scripts. add missing exe. cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jbgi committed May 4, 2021
1 parent e85d3cc commit 0c4a98f
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 123 deletions.
2 changes: 1 addition & 1 deletion custom-config/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
profileName = "default-mary";
autoStartCluster = false;
autoStartCluster = true;
useCabalRun = false;
workbenchDevMode = false;
}
119 changes: 41 additions & 78 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
let
inherit (haskellNix.internal) config;
inherit (nixpkgs) lib;
inherit (lib) head systems mapAttrs recursiveUpdate mkDefault optionalAttrs nameValuePair;
inherit (lib) head systems mapAttrs recursiveUpdate mkDefault
getAttrs optionalAttrs nameValuePair attrNames;
inherit (utils.lib) eachSystem mkApp flattenTree;
inherit (iohkNix.lib) prefixNamesWith collectExes;

Expand Down Expand Up @@ -59,87 +60,56 @@
crossSystem = systems.examples.mingwW64;
}).cardanoNodeProject.flake {};

configModule = conf:
{ pkgs, lib, ... }: {
services.cardano-node = {
stateDir = "/persist";
socketPath = "/alloc/node.socket";
enable = true;
cardanoNodePkgs = lib.mkDefault pkgs;
hostAddr = lib.mkDefault "0.0.0.0";
} // conf;
};
scripts = flattenTree pkgs.scripts;

checkNames = attrNames flake.checks;

evaluated = conf:
lib.nixosSystem {
inherit pkgs system;
modules = [ ./nix/nixos/cardano-node-service.nix (configModule conf) ];
checks =
# Linux only checks:
optionalAttrs (system == "x86_64-linux") (
prefixNamesWith "windows/" (removeAttrs
(getAttrs checkNames windowsFlake.checks)
["cardano-node-chairman:test:chairman-tests"]
)
// (prefixNamesWith "nixosTests/" (mapAttrs (_: v: v.${system} or v) pkgs.nixosTests))
)
# checks run on default system only;
// optionalAttrs (system == defaultSystem) {
hlint = pkgs.callPackage pkgs.hlintCheck {
inherit (pkgs.cardanoNodeProject.projectModule) src;
};
};

packages = let
deps = with pkgs; [
coreutils
findutils
gnugrep
gnused
postgresql
strace
lsof
dnsutils
bashInteractive
iproute
curl
netcat
bat
tree
];

vanilla = eachEnv (environment:
nameValuePair "${environment}/node-entrypoint"
(pkgs.writeShellScriptBin "cardano-node-entrypoint"
(evaluated { inherit environment; }).config.services.cardano-node.script));

debug = eachEnv (env:
let
closure = pkgs.symlinkJoin {
name = "cardano-node-entrypoint";
paths = [ vanilla."cardano-node-${env}" ] ++ deps;
};
in nameValuePair "${env}/node-entrypoint-debug" closure);

in debug // vanilla // {
exes = collectExes flake.packages;
exeNames = attrNames exes;
lazyCollectExe = p: getAttrs exeNames (collectExes p);

packages = {
inherit (devShell) devops;
} // (collectExes flake.packages)
inherit (pkgs) cardano-node-profiled cardano-node-eventlogged cardano-node-asserted;
}
// scripts
// (collectExes flake.packages)
// (prefixNamesWith "static/"
(mapAttrs pkgs.rewriteStatic (collectExes
(mapAttrs pkgs.rewriteStatic (lazyCollectExe
(if system == "x86_64-darwin" then flake else muslFlake).packages)))
# Linux only packages:
// optionalAttrs (system == "x86_64-linux") (
prefixNamesWith "windows/" (collectExes windowsFlake.packages)
// {
"dockerImage/node" = pkgs.dockerImage;
"dockerImage/submit-api" = pkgs.submitApiDockerImage;
}
);
# Linux only packages:
// optionalAttrs (system == "x86_64-linux") (
prefixNamesWith "windows/" (lazyCollectExe windowsFlake.packages)
// {
"dockerImage/node" = pkgs.dockerImage;
"dockerImage/submit-api" = pkgs.submitApiDockerImage;
}
)
# Add checks to be able to build them individually
// (prefixNamesWith "checks/" checks);

in recursiveUpdate flake {

inherit evaluated environments packages;
inherit environments packages checks;

legacyPackages = pkgs;

checks = # Linux only checks:
optionalAttrs (system == "x86_64-linux") (
prefixNamesWith "windows/" windowsFlake.checks
// (prefixNamesWith "nixosTests/" (mapAttrs (_: v: v.${system} or v) pkgs.nixosTests))
# checks run on default system only;
) // optionalAttrs (system == defaultSystem) {
hlint = pkgs.callPackage pkgs.hlintCheck {
#inherit (pkgs.cardanoNodeProject.projectModule) src;
src = ./.;
};
};

# Built by `nix build .`
defaultPackage = flake.packages."cardano-node:exe:cardano-node";

Expand All @@ -158,17 +128,10 @@
nix repl $confnix
'';
};
cardano-ping = { type = "app"; program = pkgs.cardano-ping.exePath; };
}
# nix run .#<env>/node
// (mapAttrs (_: drv: (mkApp {inherit drv;})) (flattenTree pkgs.scripts))
# nix run .#<env>/node-entrypoint
// (eachEnv (env: lib.nameValuePair "${env}/node-entrypoint" (utils.lib.mkApp {
drv = packages."${env}/node-entrypoint";
exePath = "/bin/cardano-node-entrypoint";
})))
# nix run .#<exe>
// (collectExes flake.apps);

}
) // {
overlay = import ./overlay.nix self;
Expand Down
2 changes: 1 addition & 1 deletion nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let
gitrev = if gitrev == null
then iohkNix.commitIdFromGitRepoOrZero ../.git
else gitrev;
customConfig = import ./custom-config // customConfig;
customConfig = import ../custom-config // customConfig;
inherit (pkgs.iohkNix) cardanoLib;
# commonLib: mix pkgs.lib with iohk-nix utils and our own:
commonLib = with pkgs; lib // cardanoLib // iohk-nix.lib
Expand Down
2 changes: 1 addition & 1 deletion nix/pkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final: prev: with final;
eventlog = true;
}).hsPkgs;
cardanoNodeAssertedHaskellPackages = (import ./haskell.nix {
inherit config
inherit compiler
pkgs
lib
stdenv
Expand Down
4 changes: 2 additions & 2 deletions nix/scripts-submit-api.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ let
./nixos/cardano-submit-api-service.nix
{
services.cardano-submit-api = {
network = lib.mkDefault envConfig.name;
cardanoNodePkgs = lib.mkDefault pkgs;
network = mkDefault envConfig.name;
cardanoNodePkgs = mkDefault pkgs;
};
}
];
Expand Down
26 changes: 24 additions & 2 deletions nix/scripts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ let
./nixos/cardano-node-service.nix
({config, ...}: {
services.cardano-node = {
hostAddr = mkDefault "0.0.0.0";
environment = mkDefault envConfig.name;
cardanoNodePkgs = mkDefault pkgs;
stateDir = mkDefault "state-node-${config.services.cardano-node.environment}";
runtimeDir = mkDefault null;
} // optionalAttrs (envConfig ? topology) {
topology = lib.mkDefault envConfig.topology;
topology = mkDefault envConfig.topology;
};
})
];
Expand All @@ -28,6 +29,27 @@ let
${service.script} $@
'';

in forEnvironments (environment: recurseIntoAttrs {
debugDeps = with pkgs; [
coreutils
findutils
gnugrep
gnused
postgresql
strace
lsof
dnsutils
bashInteractive
iproute
curl
netcat
bat
tree
];

in forEnvironments (environment: recurseIntoAttrs rec {
node = mkScript environment;
node-debug = pkgs.symlinkJoin {
inherit (node) name;
paths = [ node ] ++ debugDeps;
};
})
3 changes: 1 addition & 2 deletions nix/workbench/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{ lib
, stdenv

, cabal-install
, graphviz
, jq
, moreutils
Expand Down Expand Up @@ -67,7 +66,7 @@ let
'';

exeCabalOp = op: exe:
toString [ "${cabal-install}/bin/cabal" "-v0" op "exe:${exe}" "--"];
toString [ "cabal" "-v0" op "exe:${exe}" "--"];

checkoutWbMode =
if useCabalRun
Expand Down
45 changes: 9 additions & 36 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,6 @@ let
# after entering nix-shell for cabal to use nix provided dependencies for them.
clusterCabal = mkCluster (customConfig // { useCabalRun = true; });
clusterNix = mkCluster (customConfig // { useCabalRun = false; });
nixWapped = writeShellScriptBin "nix" ''
if [[ "$@" == "flake show"* ]] || [[ "$@" == "flake check"* ]]; then
echo 'Temporary override `supported-systems.nix` original content to be able to use `nix flake show|check` on dev machines (workaround for https://github.com/NixOS/nix/issues/4265)'
SYSTEMS="$(${git}/bin/git rev-parse --show-toplevel)/supported-systems.nix"
BACKUP="$(mktemp)"
mv "$SYSTEMS" "$BACKUP"
echo '[ "${system}" ]' > "$SYSTEMS"
function atexit() {
mv "$BACKUP" "$SYSTEMS"
}
trap atexit EXIT
fi
GC_DONT_GC=1 ${nixFlakes}/bin/nix "$@"
'';
cabalWapped = writeShellScriptBin "cabal" ''
# Temporary modify `cabal.project` for local builds..
PROJECT="$(${git}/bin/git rev-parse --show-toplevel)/cabal.project"
BACKUP="$(mktemp)"
cp -a "$PROJECT" "$BACKUP"
sed -ni '1,/--- 8< ---/ p' $PROJECT
function atexit() {
mv "$BACKUP" "$PROJECT"
}
trap atexit EXIT
${cabal}/bin/cabal "$@"
'';

shell = cardanoNodeProject.shellFor {
name = "cabal-dev-shell";
Expand All @@ -72,12 +46,12 @@ let
};

# These programs will be available inside the nix-shell.
buildInputs = with haskellPackages; [
nativeBuildInputs = with haskellPackages; [
cardano-ping
cabalWapped
cabalWrapped
ghcid
weeder
nixWapped
nixWrapped
pkgconfig
profiteur
profiterole
Expand Down Expand Up @@ -106,14 +80,16 @@ let
exactDeps = true;

shellHook = ''
${lib.optionalString autoStartCluster ''
function atexit() {
${lib.optionalString autoStartCluster ''
if wb local supervisord-running
then echo "workbench: stopping cluster (because 'autoStartCluster' implies this):"
stop-cluster
fi''}
fi
}
trap atexit EXIT
''}
${lib.optionalString (autoStartCluster && useCabalRun) ''
unset NIX_ENFORCE_PURITY
''}
Expand All @@ -134,8 +110,8 @@ let
devops =
stdenv.mkDerivation {
name = "devops-shell";
buildInputs = [
nixWapped
nativeBuildInputs = [
nixWrapped
cardano-cli
bech32
cardano-node
Expand All @@ -153,9 +129,6 @@ let
wb explain-mode
source <(cardano-cli --bash-completion-script cardano-cli)
source <(cardano-node --bash-completion-script cardano-node)
# Socket path default to first node launched by "start-cluster":
export CARDANO_NODE_SOCKET_PATH=$(wb local get-node-socket-path ${clusterNix.stateDir})
Expand Down

0 comments on commit 0c4a98f

Please sign in to comment.