Skip to content

WIP cardano-ops as a library #378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{ system ? builtins.currentSystem
, crossSystem ? null
, config ? {}
, deploymentGlobalsFn ? ## :: Pkgs -> GlobalsOverlayOverDefaults
pkgs:
if builtins.pathExists ../globals.nix
then import ../globals.nix pkgs
else builtins.trace "globals.nix missing, please add symlink" {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is supposed to stop evaluation, you probably want to use throw instead of trace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonringer, this is just code motion -- the original code did trace, not throw.

}:
let
defaultSourcePaths = import ./sources.nix { inherit pkgs; };
Expand Down Expand Up @@ -89,27 +94,28 @@ let
(import ./packages.nix)
];

globals =
if builtins.pathExists ../globals.nix
then [(pkgs: _: with pkgs.lib; let
buildGlobals =
specificGlobalsFn:

[(pkgs: _: with pkgs.lib; let
globalsDefault = import ../globals-defaults.nix pkgs;
globalsSpecific = import ../globals.nix pkgs;
globalsSpecific = specificGlobalsFn pkgs;
in {
globals = globalsDefault // (recursiveUpdate {
inherit (globalsDefault) ec2 libvirtd environmentVariables;
} globalsSpecific);
})]
else builtins.trace "globals.nix missing, please add symlink" [(pkgs: _: {
globals = import ../globals-defaults.nix pkgs;
})];

globals = buildGlobals deploymentGlobalsFn;

# merge upstream sources with our own:
upstream-overlay = self: super: {
inherit iohkNix;
cardano-ops = {
inherit overlays;
modules = self.importWithPkgs ../modules;
roles = self.importWithPkgs ../roles;
deployment-shell = import ./deployment-shell.nix { pkgs = self; };
};
sourcePaths = (super.sourcePaths or {}) // sourcePaths;
};
Expand All @@ -124,8 +130,8 @@ let
varnish-overlay
];

pkgs = import nixpkgs {
inherit system crossSystem config overlays;
};
pkgs = import nixpkgs {
inherit system crossSystem config overlays;
};
in
pkgs
64 changes: 64 additions & 0 deletions nix/deployment-shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
##
## This allows us to build cardano-ops-like shells with deployment capability.
##
{ pkgs }:

let
inherit (pkgs) globals lib;
nivOverrides = pkgs.writeShellScriptBin "niv-overrides" ''
niv --sources-file ${toString globals.sourcesJsonOverride} $@
'';
in
{
nativeBuildInputs =
with pkgs;
[
awscli2
bashInteractive
cardano-cli
dnsutils
niv
locli.components.exes.locli
nivOverrides
nix
nix-diff
nixops
pandoc
perl
pstree
telnet
cardano-ping
git
direnv
nix-direnv
lorri
relayUpdateTimer
] ++ (lib.optionals stdenv.hostPlatform.isLinux ([
# Those fail to compile under macOS:
node-update
# script NOT for use on mainnet:
] ++ lib.optional (globals.environmentName != "mainnet") kes-rotation));

passthru =
{
gen-graylog-creds = lib.iohk-ops-lib.scripts.gen-graylog-creds { staticPath = ./static; };
};

extraMkShellAttributes =
{
NIX_PATH = "nixpkgs=${pkgs.path}";
NIXOPS_DEPLOYMENT = "${globals.deploymentName}";
}
// globals.environmentVariables;

cardanoOpsMkShellDefault =
with pkgs;

## Note: we're using the non-rec, verbose, pkgs-relative references on purpose:
## this serves as a reference on how to define a derived shell.
mkShell
({
inherit (cardano-ops.deployment-shell) nativeBuildInputs passthru;
}
// cardano-ops.deployment-shell.extraMkShellAttributes);
}
41 changes: 3 additions & 38 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,8 @@
inherit config;
}
}:
with pkgs; with lib;
let
nivOverrides = writeShellScriptBin "niv-overrides" ''
niv --sources-file ${toString globals.sourcesJsonOverride} $@
'';

in mkShell (rec {
nativeBuildInputs = [
awscli2
bashInteractive
cardano-cli
dnsutils
niv
locli
nivOverrides
nix
nix-diff
nixops
pandoc
perl
pstree
telnet
cardano-ping
git
direnv
nix-direnv
lorri
relayUpdateTimer
] ++ (lib.optionals pkgs.stdenv.hostPlatform.isLinux ([
# Those fail to compile under macOS:
node-update
# script NOT for use on mainnet:
] ++ lib.optional (globals.environmentName != "mainnet") kes-rotation));
## See the definition of `cardanoOpsMkShellDefault` for a reference implementation
## of a cardano-ops-like shell with deployment capability.
pkgs.cardano-ops.deployment-shell.cardanoOpsMkShellDefault

NIX_PATH = "nixpkgs=${path}";
NIXOPS_DEPLOYMENT = "${globals.deploymentName}";
passthru = {
gen-graylog-creds = iohk-ops-lib.scripts.gen-graylog-creds { staticPath = ./static; };
};
} // globals.environmentVariables)