mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 12:29:19 -08:00
fix(exports): enable base services by default
This commit is contained in:
parent
77fd991ed1
commit
a1273971d9
14 changed files with 36 additions and 67 deletions
|
|
@ -3,8 +3,27 @@
|
|||
gensokyo-zone,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (gensokyo-zone.lib) mapListToAttrs mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.attrsets) nameValuePair;
|
||||
mkExporter = { name, port }: nameValuePair "prometheus-exporters-${name}" ({config, ...}: {
|
||||
nixos = {
|
||||
serviceAttrPath = ["services" "prometheus" "exporters" name];
|
||||
assertions = mkIf config.enable [
|
||||
(nixosConfig: {
|
||||
assertion = config.ports.default.port == nixosConfig.services.prometheus.exporters.${name}.port;
|
||||
message = "port mismatch";
|
||||
})
|
||||
];
|
||||
};
|
||||
ports.default = mapAlmostOptionDefaults {
|
||||
inherit port;
|
||||
protocol = "http";
|
||||
};
|
||||
});
|
||||
exporters = mapListToAttrs mkExporter [
|
||||
{ name = "node"; port = 9091; }
|
||||
];
|
||||
in {
|
||||
config.exports.services = {
|
||||
prometheus = {config, ...}: {
|
||||
|
|
@ -23,22 +42,6 @@ in {
|
|||
protocol = "http";
|
||||
};
|
||||
};
|
||||
prometheus-exporters-node = {config, ...}: {
|
||||
id = mkAlmostOptionDefault "prometheus-exporters-node";
|
||||
nixos = {
|
||||
serviceAttrPath = ["services" "prometheus" "exporters" "node"];
|
||||
assertions = mkIf config.enable [
|
||||
(nixosConfig: {
|
||||
assertion = config.ports.default.port == nixosConfig.services.prometheus.exporters.node.port;
|
||||
message = "port mismatch";
|
||||
})
|
||||
];
|
||||
};
|
||||
ports.default = mapAlmostOptionDefaults {
|
||||
port = 9091;
|
||||
protocol = "http";
|
||||
};
|
||||
};
|
||||
grafana = {config, ...}: {
|
||||
id = mkAlmostOptionDefault "grafana";
|
||||
nixos = {
|
||||
|
|
@ -87,5 +90,5 @@ in {
|
|||
protocol = "http";
|
||||
};
|
||||
};
|
||||
};
|
||||
} // exporters;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@
|
|||
inherit (gensokyo-zone.lib) mkAlmostOptionDefault;
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib.modules) mkIf mkMerge mkOptionDefault;
|
||||
inherit (lib.attrsets) mapAttrsToList getAttrFromPath;
|
||||
inherit (lib.attrsets) mapAttrsToList getAttrFromPath genAttrs;
|
||||
inherit (lib.trivial) mapNullable;
|
||||
inherit (lib.strings) concatStringsSep;
|
||||
systemConfig = config;
|
||||
cfg = config.exports;
|
||||
portModule = {
|
||||
config,
|
||||
service,
|
||||
|
|
@ -146,12 +146,15 @@
|
|||
};
|
||||
in {
|
||||
options.exports = with lib.types; {
|
||||
defaultServices = mkEnableOption "common base services" // {
|
||||
default = config.type == "NixOS";
|
||||
};
|
||||
services = mkOption {
|
||||
type = attrsOf (submoduleWith {
|
||||
modules = [serviceModule];
|
||||
specialArgs = {
|
||||
machine = name;
|
||||
inherit systemConfig;
|
||||
systemConfig = config;
|
||||
};
|
||||
});
|
||||
default = {};
|
||||
|
|
@ -162,5 +165,14 @@ in {
|
|||
modules = mkIf (config.type == "NixOS") [
|
||||
nixosModule
|
||||
];
|
||||
exports = let
|
||||
defaultServices = genAttrs [
|
||||
"sshd"
|
||||
"prometheus-exporters-node"
|
||||
"promtail"
|
||||
] (_: { enable = mkAlmostOptionDefault true; });
|
||||
in {
|
||||
services = mkIf cfg.defaultServices defaultServices;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue