Skip to content

Commit

Permalink
nixos service: add extraNodeConfig option, improve types.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbgi committed Sep 16, 2021
1 parent 421fabd commit 97c4236
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions nix/nixos/cardano-node-service.nix
Expand Up @@ -9,33 +9,26 @@ let
inherit (cfg.cardanoNodePkgs) commonLib cardano-node cardano-node-profiled cardano-node-eventlogged cardano-node-asserted;
envConfig = cfg.environments.${cfg.environment};
runtimeDir = if cfg.runtimeDir == null then cfg.stateDir else "/run/${cfg.runtimeDir}";
mkScript = cfg: i: let
instanceConfig =
cfg.nodeConfig
//
(optionalAttrs (cfg.nodeConfig ? hasEKG)
{
hasEKG = cfg.nodeConfig.hasEKG + i;
})
//
(optionalAttrs (cfg.nodeConfig ? hasPrometheus)
{
hasPrometheus = map (n: if isInt n then n + i else n) cfg.nodeConfig.hasPrometheus;
})
//
(foldl' (x: y: x // y) {}
(mapAttrsToList
(era: epoch:
{ "Test${era}HardForkAtEpoch" = epoch;
})
cfg.forceHardForks))
mkScript = cfg:
let baseConfig = recursiveUpdate (cfg.nodeConfig
// (mapAttrs' (era: epoch:
nameValuePair "Test${era}HardForkAtEpoch" epoch
) cfg.forceHardForks)
// (optionalAttrs cfg.useNewTopology {
EnableP2P = true;
TargetNumberOfRootPeers = cfg.targetNumberOfRootPeers;
TargetNumberOfKnownPeers = cfg.targetNumberOfKnownPeers;
TargetNumberOfEstablishedPeers = cfg.targetNumberOfEstablishedPeers;
TargetNumberOfActivePeers = cfg.targetNumberOfActivePeers;
});
})) cfg.extraNodeConfig;
in i: let
instanceConfig = recursiveUpdate (baseConfig
// (optionalAttrs (baseConfig ? hasEKG) {
hasEKG = baseConfig.hasEKG + i;
})
// (optionalAttrs (baseConfig ? hasPrometheus) {
hasPrometheus = map (n: if isInt n then n + i else n) baseConfig.hasPrometheus;
})) (cfg.extraNodeInstanceConfig i);
nodeConfigFile = if (cfg.nodeConfigFile != null) then cfg.nodeConfigFile
else toFile "config-${toString cfg.nodeId}-${toString i}.json" (toJSON instanceConfig);
newTopology = {
Expand Down Expand Up @@ -303,8 +296,7 @@ in {
};

extraServiceConfig = mkOption {
# activate type for nixos-21.03:
type = types.unspecified # types.functionTo (types.listOf types.attrs);
type = types.functionTo types.attrs
// {
merge = loc: foldl' (res: def: i: recursiveUpdate (res i) (def.value i)) (i: {});
};
Expand All @@ -315,8 +307,7 @@ in {
};

extraSocketConfig = mkOption {
# activate type for nixos-21.03:
type = types.unspecified # types.functionTo (types.listOf types.attrs);
type = types.functionTo types.attrs
// {
merge = loc: foldl' (res: def: i: recursiveUpdate (res i) (def.value i)) (i: {});
};
Expand Down Expand Up @@ -405,8 +396,7 @@ in {
};

instanceProducers = mkOption {
# activate type for nixos-21.03:
# type = types.functionTo (types.listOf types.attrs);
type = types.functionTo (types.listOf types.attrs);
default = _: [];
description = ''
Static routes to local peers, specific to a given instance (when multiple instances are used).
Expand Down Expand Up @@ -480,14 +470,31 @@ in {
'';
};

extraNodeConfig = mkOption {
type = types.attrs // {
merge = loc: foldl' (res: def: recursiveUpdate res def.value) {};
};
default = {};
description = ''Additional node config.'';
};

extraNodeInstanceConfig = mkOption {
type = types.functionTo types.attrs
// {
merge = loc: foldl' (res: def: i: recursiveUpdate (res i) (def.value i)) (i: {});
};
default = i: {};
description = ''Additional node config for a particular instance.'';
};

nodeConfigFile = mkOption {
type = types.nullOr types.str;
default = null;
description = ''Actual configuration file (shell expression).'';
};

forceHardForks = mkOption {
type = types.attrs;
type = types.attrsOf types.int;
default = {};
description = ''
A developer-oriented dictionary option to force hard forks for given eras at given epochs. Maps capitalised era names (Shelley, Allegra, Mary, etc.) to hard fork epoch number.
Expand Down

0 comments on commit 97c4236

Please sign in to comment.