nixos/applications/_base.nix

99 lines
2.1 KiB
Nix
Raw Normal View History

{
config,
lib,
pkgs,
...
}:
with lib; let
# root service
cfg = config.services.skynet;
in {
imports = [
# every server needs to have a dns record
./dns/dns.nix
# every server should have proper certs
./acme.nix
./nginx.nix
# every server may need the firewall config stuff
./firewall.nix
# every server needs teh ldap client for admins
./ldap/client.nix
# every server will need the config to backup to
./restic.nix
# every server will be monitored for grafana
./prometheus.nix
];
options.services.skynet = {
# since we use this basically everywhere provide a standard way to set it
host = {
ip = mkOption {
type = types.str;
};
name = mkOption {
type = types.str;
};
hostname = mkOption {
type = types.str;
default = "${cfg.host.name}.skynet.ie";
};
interface = mkOption {
type = types.str;
description = "Will most likely be ``eno1`` for physical servers.";
default = "eth0";
};
cidr = mkOption {
type = types.int;
description = "Most of our servers are /26, ";
default = 26;
};
};
};
config = {
services.skynet.dns.records = [
{
record = cfg.host.name;
r_type = "A";
value = cfg.host.ip;
server = true;
}
{
record = cfg.host.ip;
r_type = "PTR";
value = cfg.host.hostname;
}
];
# set
networking = {
hostName = cfg.host.name;
defaultGateway.interface = lib.mkForce cfg.host.interface;
# needs to have an address statically assigned
interfaces."${cfg.host.interface}".ipv4.addresses = [
{
address = cfg.host.ip;
prefixLength = cfg.host.cidr;
}
];
};
services.nginx = {
virtualHosts = {
# for every server unless explisitly defined redirect the ip to skynet.ie
"${cfg.host.ip}" = {
forceSSL = true;
useACMEHost = "skynet";
locations."/".return = "307 https://skynet.ie";
};
};
};
};
}