2023-05-01 11:37:33 +02:00
|
|
|
{ self, nixpkgs, agenix, nixos-exporter, solid-xmpp-alarm, ... }@inputs:
|
2023-03-23 16:45:30 +01:00
|
|
|
|
|
|
|
rec {
|
2023-04-16 16:37:11 +02:00
|
|
|
generateNixosSystem = {
|
|
|
|
name,
|
|
|
|
system ? "x86_64-linux",
|
2023-04-21 23:03:11 +02:00
|
|
|
group ? null,
|
2023-04-16 16:37:11 +02:00
|
|
|
}: let
|
2023-03-23 17:09:54 +01:00
|
|
|
localNixpkgs = nixpkgs.lib.attrByPath [ "nixpkgs-${name}" ] nixpkgs inputs;
|
|
|
|
in localNixpkgs.lib.nixosSystem {
|
2023-04-16 16:37:11 +02:00
|
|
|
system = system;
|
2023-03-23 16:45:30 +01:00
|
|
|
modules = [
|
|
|
|
({ ... }: {
|
|
|
|
/*
|
|
|
|
Make the contents of the flake availiable to modules.
|
|
|
|
Useful for having the monitoring server scraping the
|
|
|
|
target config from all other servers automatically.
|
|
|
|
*/
|
|
|
|
_module.args._nixfiles = self;
|
|
|
|
})
|
|
|
|
../configuration/common
|
2023-05-01 12:23:09 +02:00
|
|
|
../users/clerie
|
2023-03-23 16:45:30 +01:00
|
|
|
({ ... }: {
|
|
|
|
nixpkgs.overlays = [
|
|
|
|
(_: _: {
|
2023-05-01 12:29:55 +02:00
|
|
|
inherit (agenix.packages."x86_64-linux")
|
|
|
|
agenix;
|
2023-03-23 16:45:30 +01:00
|
|
|
inherit (nixos-exporter.packages."x86_64-linux")
|
|
|
|
nixos-exporter;
|
|
|
|
})
|
|
|
|
];
|
2023-04-21 23:03:11 +02:00
|
|
|
clerie.monitoring = nixpkgs.lib.attrsets.optionalAttrs (group != null) { serviceLevel = group; };
|
2023-03-23 16:45:30 +01:00
|
|
|
})
|
2023-05-01 11:37:33 +02:00
|
|
|
agenix.nixosModules.default
|
2023-03-23 16:45:30 +01:00
|
|
|
solid-xmpp-alarm.nixosModules.solid-xmpp-alarm
|
|
|
|
(../hosts + "/${name}/configuration.nix")
|
2023-05-01 12:09:47 +02:00
|
|
|
# Automatically load secrets from the hosts secrets directory
|
|
|
|
({ lib, ... }: let
|
|
|
|
secretsPath = ../hosts + "/${name}/secrets";
|
|
|
|
in {
|
|
|
|
age.secrets = lib.mapAttrs' (filename: _: lib.nameValuePair (lib.removeSuffix ".age" filename) {
|
|
|
|
file = secretsPath + "/${filename}";
|
|
|
|
}) (lib.filterAttrs (name: type: (type == "regular") && (lib.hasSuffix ".age" name) ) (if builtins.pathExists secretsPath then builtins.readDir secretsPath else {}));
|
|
|
|
})
|
2023-03-23 16:45:30 +01:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2023-04-16 16:37:11 +02:00
|
|
|
mapToNixosConfigurations = hosts: builtins.mapAttrs (name: host: generateNixosSystem host) hosts;
|
|
|
|
|
2023-03-23 16:45:30 +01:00
|
|
|
generateColmenaHost = name: hostSystem: {
|
|
|
|
deployment = {
|
|
|
|
targetHost = "${name}.net.clerie.de";
|
|
|
|
targetUser = null;
|
2023-04-21 23:03:11 +02:00
|
|
|
tags = let
|
|
|
|
group = nixpkgs.lib.attrByPath [ "clerie" "monitoring" "serviceLevel" ] null hostSystem.config;
|
|
|
|
in nixpkgs.lib.lists.optional (group != null) group;
|
2023-03-23 16:45:30 +01:00
|
|
|
};
|
|
|
|
nixpkgs.system = hostSystem.config.nixpkgs.system;
|
|
|
|
imports = hostSystem._module.args.modules;
|
|
|
|
deployment.allowLocalDeployment = builtins.any (n: n == name) [ "schule" "osmium" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
mapToColmenaHosts = hosts: builtins.mapAttrs (generateColmenaHost) hosts;
|
|
|
|
|
2023-04-16 15:50:10 +02:00
|
|
|
buildHosts = hosts: builtins.mapAttrs (name: host: host.config.system.build.toplevel) (nixpkgs.lib.filterAttrs (name: host: (builtins.substring 0 1 name) != "_") hosts);
|
2023-03-23 16:45:30 +01:00
|
|
|
}
|