diff --git a/cluster/default.nix b/cluster/default.nix index e3e4ce4..6eaf70d 100644 --- a/cluster/default.nix +++ b/cluster/default.nix @@ -1,6 +1,9 @@ -{ lib, hostName }: +{ lib, depot, hostName }: lib.evalModules { + specialArgs = { + inherit depot; + }; modules = [ # Arbitrary variables to reference across multiple services ./lib/vars @@ -10,7 +13,6 @@ lib.evalModules { ../modules/port-magic ../tools/inject.nix - ./lib/load-hosts.nix ./lib/services.nix ./lib/inject-nixos-config.nix ./lib/port-magic-multi.nix diff --git a/cluster/inject.nix b/cluster/inject.nix index 66ffb22..f9052a2 100644 --- a/cluster/inject.nix +++ b/cluster/inject.nix @@ -1,8 +1,8 @@ hostName: -{ lib, ... }: +{ depot, lib, ... }: let - cluster = import ./. { inherit lib hostName; }; + cluster = import ./. { inherit lib depot hostName; }; in { diff --git a/cluster/lib/load-hosts.nix b/cluster/lib/load-hosts.nix deleted file mode 100644 index 3b86f67..0000000 --- a/cluster/lib/load-hosts.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ config, lib, ... }: -let - hosts = import ../../hosts; - self = hosts.${config.vars.hostName}; - others = lib.filterAttrs (_: host: host != self) hosts; -in -{ - config.vars.hosts = hosts // { inherit self others; }; -} diff --git a/cluster/services/consul/remote-api.nix b/cluster/services/consul/remote-api.nix index 14cefb8..7725175 100644 --- a/cluster/services/consul/remote-api.nix +++ b/cluster/services/consul/remote-api.nix @@ -1,16 +1,14 @@ -{ config, cluster, hosts, lib, tools, ... }: +{ config, cluster, depot, lib, tools, ... }: let inherit (tools.meta) domain; - inherit (config.networking) hostName; - - hyprspaceConfig = hosts.${hostName}.hypr; + inherit (depot.reflection) hyprspace; frontendDomain = "consul-remote.internal.${domain}"; in { services.nginx.virtualHosts.${frontendDomain} = tools.nginx.vhosts.proxy "http://127.0.0.1:8500" // { - listenAddresses = lib.singleton hyprspaceConfig.addr; + listenAddresses = lib.singleton hyprspace.addr; enableACME = false; useACMEHost = "internal.${domain}"; }; @@ -20,13 +18,13 @@ in mode = "external"; definition = { name = "consul-remote"; - address = hyprspaceConfig.addr; + address = hyprspace.addr; port = 443; checks = [ { name = "Frontend"; id = "service:consul-remote:frontend"; - http = "https://${hyprspaceConfig.addr}/v1/status/leader"; + http = "https://${hyprspace.addr}/v1/status/leader"; tls_server_name = frontendDomain; interval = "60s"; } diff --git a/cluster/services/dns/authoritative.nix b/cluster/services/dns/authoritative.nix index 99d2bfb..30326f4 100644 --- a/cluster/services/dns/authoritative.nix +++ b/cluster/services/dns/authoritative.nix @@ -1,7 +1,7 @@ -{ cluster, config, hosts, lib, tools, ... }: +{ cluster, config, depot, lib, tools, ... }: let - inherit (hosts.${config.networking.hostName}) interfaces; + inherit (depot.reflection) interfaces; inherit (tools.meta) domain; patroni = cluster.config.links.patroni-pg-access; diff --git a/cluster/services/dns/coredns.nix b/cluster/services/dns/coredns.nix index e92247d..a991914 100644 --- a/cluster/services/dns/coredns.nix +++ b/cluster/services/dns/coredns.nix @@ -1,10 +1,10 @@ -{ config, hosts, inputs, lib, pkgs, tools, ... }: +{ config, depot, lib, pkgs, tools, ... }: let - inherit (hosts.${config.networking.hostName}) interfaces; + inherit (depot.reflection) interfaces; inherit (tools.meta) domain; inherit (config.links) localRecursor; - inherit (inputs.self.packages.${pkgs.system}) stevenblack-hosts; + inherit (depot.packages) stevenblack-hosts; dot = config.security.acme.certs."securedns.${domain}"; in diff --git a/cluster/services/dns/default.nix b/cluster/services/dns/default.nix index 6786ad2..18edb9f 100644 --- a/cluster/services/dns/default.nix +++ b/cluster/services/dns/default.nix @@ -1,7 +1,7 @@ -{ config, ... }: +{ config, depot, ... }: let - inherit (config.vars) hosts; + inherit (depot.config) hours; in { vars.pdns-api-key-secret = { @@ -10,7 +10,7 @@ in }; links = { dnsResolver = { - ipv4 = hosts.VEGAS.interfaces.vstub.addr; + ipv4 = hours.VEGAS.interfaces.vstub.addr; port = 53; }; powerdns-api = { diff --git a/cluster/services/hercules-ci-multi-agent/common.nix b/cluster/services/hercules-ci-multi-agent/common.nix index fc4bc77..707f90e 100644 --- a/cluster/services/hercules-ci-multi-agent/common.nix +++ b/cluster/services/hercules-ci-multi-agent/common.nix @@ -1,4 +1,4 @@ -{ config, inputs, lib, pkgs, ... }: +{ config, depot, lib, pkgs, ... }: let mapAgents = lib.flip lib.mapAttrs config.services.hercules-ci-agents; @@ -17,7 +17,7 @@ let in { imports = [ - inputs.hercules-ci-agent.nixosModules.multi-agent-service + depot.inputs.hercules-ci-agent.nixosModules.multi-agent-service ]; age.secrets = mergeMap (name: _: { diff --git a/cluster/services/hercules-ci-multi-agent/orgs/max.nix b/cluster/services/hercules-ci-multi-agent/orgs/max.nix index a74e9c6..55c360d 100644 --- a/cluster/services/hercules-ci-multi-agent/orgs/max.nix +++ b/cluster/services/hercules-ci-multi-agent/orgs/max.nix @@ -1,8 +1,8 @@ -{ config, lib, inputs, pkgs, ... }: +{ config, lib, depot, pkgs, ... }: { services.hercules-ci-agents.max = { - package = lib.mkForce inputs.self.packages.${pkgs.system}.hercules-ci-agent; + package = lib.mkForce depot.packages.hercules-ci-agent; settings = { clusterJoinTokenPath = config.age.secrets.hci-token-max.path; binaryCachesPath = config.age.secrets.hci-cache-config-max.path; diff --git a/cluster/services/hercules-ci-multi-agent/orgs/nixpak.nix b/cluster/services/hercules-ci-multi-agent/orgs/nixpak.nix index 44909b6..ac0087e 100644 --- a/cluster/services/hercules-ci-multi-agent/orgs/nixpak.nix +++ b/cluster/services/hercules-ci-multi-agent/orgs/nixpak.nix @@ -1,8 +1,8 @@ -{ config, lib, inputs, pkgs, ... }: +{ config, lib, depot, pkgs, ... }: { services.hercules-ci-agents.nixpak = { - package = lib.mkForce inputs.self.packages.${pkgs.system}.hercules-ci-agent; + package = lib.mkForce depot.packages.hercules-ci-agent; settings = { clusterJoinTokenPath = config.age.secrets.hci-token-nixpak.path; binaryCachesPath = config.age.secrets.hci-cache-config-nixpak.path; diff --git a/cluster/services/hercules-ci-multi-agent/orgs/private-void.nix b/cluster/services/hercules-ci-multi-agent/orgs/private-void.nix index eb9619f..f60f4e8 100644 --- a/cluster/services/hercules-ci-multi-agent/orgs/private-void.nix +++ b/cluster/services/hercules-ci-multi-agent/orgs/private-void.nix @@ -1,8 +1,8 @@ -{ config, lib, inputs, pkgs, ... }: +{ config, lib, depot, pkgs, ... }: { services.hercules-ci-agents.private-void = { - package = lib.mkForce inputs.self.packages.${pkgs.system}.hercules-ci-agent; + package = lib.mkForce depot.packages.hercules-ci-agent; settings = { clusterJoinTokenPath = config.age.secrets.hci-token-private-void.path; binaryCachesPath = config.age.secrets.hci-cache-config-private-void.path; diff --git a/cluster/services/ipfs/cluster.nix b/cluster/services/ipfs/cluster.nix index 83844dc..2a8f1b1 100644 --- a/cluster/services/ipfs/cluster.nix +++ b/cluster/services/ipfs/cluster.nix @@ -1,4 +1,4 @@ -{ aspect, config, inputs, lib, pkgs, tools, ... }: +{ config, depot, lib, pkgs, tools, ... }: let inherit (tools.meta) domain; @@ -11,7 +11,7 @@ let proxySocket = "/run/ipfs-cluster/ipfs-api-proxy.sock"; in { imports = [ - aspect.modules.ipfs-cluster + depot.nixosModules.ipfs-cluster ]; age.secrets = { @@ -24,7 +24,7 @@ in { services.ipfs-cluster = { enable = true; - package = inputs.self.packages.${pkgs.system}.ipfs-cluster; + package = depot.packages.ipfs-cluster; consensus = "crdt"; dataDir = "/srv/storage/ipfs/cluster"; secretFile = config.age.secrets.ipfs-cluster-secret.path; diff --git a/cluster/services/ipfs/default.nix b/cluster/services/ipfs/default.nix index 6eaa468..db3a837 100644 --- a/cluster/services/ipfs/default.nix +++ b/cluster/services/ipfs/default.nix @@ -1,8 +1,8 @@ -{ config, lib, tools, ... }: +{ config, depot, lib, tools, ... }: { hostLinks = lib.genAttrs config.services.ipfs.nodes.node (name: let - host = config.vars.hosts.${name}; + host = depot.reflection; intf = host.interfaces.primary; self = config.hostLinks.${name}.ipfs; in { diff --git a/cluster/services/ipfs/gateway.nix b/cluster/services/ipfs/gateway.nix index ec22343..c37727e 100644 --- a/cluster/services/ipfs/gateway.nix +++ b/cluster/services/ipfs/gateway.nix @@ -1,4 +1,4 @@ -{ config, hosts, tools, ... }: +{ config, depot, tools, ... }: with tools.nginx; let inherit (tools.meta) domain; @@ -64,7 +64,7 @@ in extraConfig = '' access_log off; auth_request off; - allow ${hosts.VEGAS.interfaces.primary.addr}; + allow ${depot.config.hours.VEGAS.interfaces.primary.addr}; deny all; ''; }; diff --git a/cluster/services/ipfs/node.nix b/cluster/services/ipfs/node.nix index ee86503..454d800 100644 --- a/cluster/services/ipfs/node.nix +++ b/cluster/services/ipfs/node.nix @@ -1,4 +1,4 @@ -{ aspect, cluster, config, inputs, lib, hosts, pkgs, tools, ... }: +{ cluster, config, depot, lib, pkgs, tools, ... }: let inherit (tools.meta) domain; cfg = config.services.ipfs; @@ -9,7 +9,7 @@ let in { imports = [ - aspect.modules.ipfs + depot.nixosModules.ipfs ]; links.ipfsGateway.protocol = "http"; @@ -21,7 +21,7 @@ in services.ipfs = { enable = true; - package = inputs.self.packages.${pkgs.system}.ipfs; + package = depot.packages.ipfs; startWhenNeeded = false; autoMount = true; autoMigrate = false; @@ -40,7 +40,7 @@ in extraFlags = [ "--migrate" ]; extraConfig = { Bootstrap = [ - "/ip4/${hosts.VEGAS.interfaces.primary.addr}/tcp/${toString ipfsPort}/p2p/Qmd7QHZU8UjfYdwmjmq1SBh9pvER9AwHpfwQvnvNo3HBBo" + "/ip4/${depot.config.hours.VEGAS.interfaces.primary.addr}/tcp/${toString ipfsPort}/p2p/Qmd7QHZU8UjfYdwmjmq1SBh9pvER9AwHpfwQvnvNo3HBBo" "/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa" "/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb" "/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN" diff --git a/cluster/services/patroni/worker.nix b/cluster/services/patroni/worker.nix index 297c5ac..21ea484 100644 --- a/cluster/services/patroni/worker.nix +++ b/cluster/services/patroni/worker.nix @@ -1,4 +1,4 @@ -{ aspect, cluster, config, lib, pkgs, ... }: +{ cluster, config, depot, lib, pkgs, ... }: let inherit (cluster.config) vars; @@ -14,7 +14,7 @@ in { imports = [ - aspect.modules.patroni + depot.nixosModules.patroni ]; age.secrets = lib.mapAttrs (_: file: { diff --git a/cluster/services/websites/host.nix b/cluster/services/websites/host.nix index c26d1c1..1ae37e0 100644 --- a/cluster/services/websites/host.nix +++ b/cluster/services/websites/host.nix @@ -1,9 +1,9 @@ -{ config, inputs, lib, pkgs, tools, ... }: +{ config, depot, lib, pkgs, tools, ... }: let importWebsites = expr: import expr { tools = tools.nginx; - packages = inputs.self.packages.${pkgs.system}; + inherit (depot) packages; }; websites = tools.nginx.mappers.mapSubdomains (importWebsites ./websites.nix); diff --git a/cluster/services/wireguard/default.nix b/cluster/services/wireguard/default.nix index 50b6114..b8a0ffb 100644 --- a/cluster/services/wireguard/default.nix +++ b/cluster/services/wireguard/default.nix @@ -1,7 +1,7 @@ -{ config, ... }: +{ config, depot, ... }: let - inherit (config.vars) hosts; + inherit (depot.config) hours; meshNet = rec { netAddr = "10.1.1.0"; @@ -9,7 +9,7 @@ let cidr = "${netAddr}/${toString prefix}"; }; - getExtAddr = host: host.interfaces.primary.addrPublic or host.interfaces.primary.addr; + getExtAddr = host: host.interfaces.primary.addrPublic; in { vars = { @@ -22,7 +22,7 @@ in }; links = { mesh-node-checkmate = { - ipv4 = getExtAddr hosts.checkmate; + ipv4 = getExtAddr hours.checkmate; extra = { meshIp = "10.1.1.32"; inherit meshNet; @@ -32,17 +32,17 @@ in }; }; mesh-node-VEGAS = { - ipv4 = getExtAddr hosts.VEGAS; + ipv4 = getExtAddr hours.VEGAS; extra = { meshIp = "10.1.1.5"; inherit meshNet; pubKey = "NpeB8O4erGTas1pz6Pt7qtY9k45YV6tcZmvvA4qXoFk="; privKeyFile = ./mesh-keys/VEGAS.age; - extraRoutes = [ "${hosts.VEGAS.interfaces.vstub.addr}/32" "10.10.0.0/16" ]; + extraRoutes = [ "${hours.VEGAS.interfaces.vstub.addr}/32" "10.10.0.0/16" ]; }; }; mesh-node-prophet = { - ipv4 = getExtAddr hosts.prophet; + ipv4 = getExtAddr hours.prophet; extra = { meshIp = "10.1.1.9"; inherit meshNet; diff --git a/flake.nix b/flake.nix index e803d8f..dd105ed 100644 --- a/flake.nix +++ b/flake.nix @@ -7,88 +7,15 @@ }; outputs = { self, nixpkgs, flake-parts, ... }@inputs: - let + flake-parts.lib.mkFlake { inherit inputs; } { systems = [ "x86_64-linux" "aarch64-linux" ]; - nixpkgsFor = nixpkgs.legacyPackages; - - inherit (nixpkgs) lib; - - aspect = import ./modules inputs; - hosts = import ./hosts; - - nixosHosts' = lib.filterAttrs (_: host: host ? nixos) hosts; - - nixosHosts = lib.attrNames nixosHosts'; - - deployableNixosHosts' = lib.filterAttrs (_: host: host ? container -> !host.container) nixosHosts'; - - deployableNixosHosts = lib.attrNames deployableNixosHosts'; - - meta = import ./tools/meta.nix; - - specialArgs = { - inherit inputs hosts aspect; - toolsets = import ./tools; - }; - mkNixOS' = lib: name: let host = hosts.${name}; in lib.nixosSystem { - inherit specialArgs; - system = "${host.arch}-linux"; - modules = [ host.nixos ./tools/inject.nix (import ./cluster/inject.nix name) ]; - }; - mkNixOS = mkNixOS' lib; - - mkDeployEffect = branch: name: host: let - subdomain = host.enterprise.subdomain or "services"; - hostname = "${lib.toLower name}.${subdomain}.${meta.domain}"; - in effects.runIf (branch == "master" || branch == "staging") (effects.runNixOS { - requiredSystemFeatures = [ "hci-deploy-agent-nixos" ]; - inherit (self.nixosConfigurations.${name}) config; - secretsMap.ssh = "deploy-ssh"; - - userSetupScript = '' - writeSSHKey ssh - cat >>~/.ssh/known_hosts <>~/.ssh/known_hosts <