-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from ralexstokes/optional-nixos-module
refactor nixos module into "submodules" per component
- Loading branch information
Showing
3 changed files
with
75 additions
and
65 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
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 |
---|---|---|
@@ -1,66 +1,83 @@ | ||
pkg: | ||
{ config, lib, pkgs, ... }: | ||
let | ||
cfg = config.services.mev-rs; | ||
|
||
component = cfg.enable; | ||
# ensure the intended component is part of the feature set | ||
features = if lib.strings.hasInfix component cfg.features then cfg.features else lib.strings.removePrefix "," "${cfg.features},${component}"; | ||
|
||
mev-rs = pkg.mev-rs { | ||
mev-rs-with-features = features: pkg.mev-rs { | ||
inherit features; | ||
system = pkgs.system; | ||
}; | ||
|
||
name = "mev-${cfg.enable}-rs"; | ||
|
||
cmd = '' | ||
${mev-rs}/bin/mev \ | ||
${component} \ | ||
${cfg.config-file} | ||
''; | ||
in | ||
{ | ||
options.services.mev-rs = { | ||
enable = lib.mkOption { | ||
type = lib.types.enum [ "boost" "build" ]; | ||
description = "which subcommand of `mev-rs` to run"; | ||
}; | ||
config-file = lib.mkOption { | ||
type = lib.types.str; | ||
description = '' | ||
path to a config file suitable for the `mev-rs` toolkit | ||
''; | ||
}; | ||
features = lib.mkOption { | ||
type = lib.types.str; | ||
default = cfg.enable; | ||
description = '' | ||
feature set (comma-separated) to enable for `cargo` build | ||
mev-rs-submodule = for-component: { config, ... }: with lib; with types; | ||
let | ||
features = strings.concatStringsSep "," [ for-component ] ++ config.additional-features; | ||
mev-rs = mev-rs-with-features features; | ||
name = "mev-${for-component}-rs"; | ||
cmd = '' | ||
${mev-rs}/bin/mev \ | ||
${for-component} \ | ||
${config.config-file} | ||
''; | ||
}; | ||
}; | ||
|
||
config = { | ||
networking.firewall = lib.mkIf (component == "build") { | ||
allowedTCPPorts = [ 30303 ]; | ||
allowedUDPPorts = [ 30303 ]; | ||
}; | ||
|
||
environment.systemPackages = [ | ||
mev-rs | ||
]; | ||
in | ||
{ | ||
options = { | ||
component = mkOption { | ||
type = enum [ "boost" "relay" "build" ]; | ||
default = for-component; | ||
}; | ||
config-file = mkOption { | ||
type = str; | ||
description = '' | ||
path to a config file suitable for the `mev-rs` toolkit | ||
''; | ||
}; | ||
additional-features = mkOption { | ||
type = listOf str; | ||
description = '' | ||
additional Cargo features to include alongside those required for the `component` | ||
''; | ||
}; | ||
after-systemd-service = mkOption { | ||
type = str; | ||
default = "vc.service"; | ||
description = '' | ||
the name of a systemd service to wait activation of before activating this unit | ||
''; | ||
}; | ||
}; | ||
config = { | ||
environment.systemPackages = [ | ||
mev-rs | ||
]; | ||
networking.firewall = lib.mkIf (for-component == "build") { | ||
allowedTCPPorts = [ 30303 ]; | ||
allowedUDPPorts = [ 30303 ]; | ||
}; | ||
|
||
systemd.services."${name}" = { | ||
description = name; | ||
wantedBy = [ "multi-user.target" ]; | ||
after = [ "vc.service" ]; | ||
serviceConfig = { | ||
ExecStart = cmd; | ||
Restart = "on-failure"; | ||
RestartSec = "10s"; | ||
SyslogIdentifier = name; | ||
systemd.services."${name}" = { | ||
description = name; | ||
wantedBy = [ "multi-user.target" ]; | ||
after = [ config.after-systemd-service ]; | ||
serviceConfig = { | ||
ExecStart = cmd; | ||
Restart = "on-failure"; | ||
RestartSec = "10s"; | ||
SyslogIdentifier = for-component; | ||
}; | ||
}; | ||
}; | ||
}; | ||
in | ||
{ | ||
options.services.mev-rs = with lib; with types; mkOption { | ||
type = listOf (submodule { | ||
options.boost = mkOption { | ||
type = attrsOf (submodule mev-rs-submodule "boost"); | ||
}; | ||
options.relay = mkOption { | ||
type = attrsOf (submodule mev-rs-submodule "relay"); | ||
}; | ||
options.build = mkOption { | ||
type = attrsOf (submodule mev-rs-submodule "build"); | ||
}; | ||
}); | ||
}; | ||
} |