2024-05-13 17:39:54 +02:00
|
|
|
{ self
|
|
|
|
, nixpkgs
|
|
|
|
, ...
|
|
|
|
}@inputs:
|
2023-03-23 16:45:30 +01:00
|
|
|
|
2024-05-13 17:39:54 +02:00
|
|
|
let
|
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-06-30 23:31:13 +02:00
|
|
|
modules ? [],
|
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-06-30 23:31:13 +02:00
|
|
|
modules = modules ++ [
|
2024-05-13 16:44:21 +02:00
|
|
|
self.nixosModules.nixfilesInputs
|
2024-05-13 16:33:20 +02:00
|
|
|
self.nixosModules.clerie
|
2024-05-13 17:00:03 +02:00
|
|
|
|
|
|
|
({ config, lib, ... }: {
|
|
|
|
# Apply overlays
|
|
|
|
nixpkgs.overlays = [
|
|
|
|
self.overlays.nixfilesInputs
|
|
|
|
self.overlays.clerie
|
|
|
|
];
|
|
|
|
|
2023-03-23 16:45:30 +01:00
|
|
|
/*
|
|
|
|
Make the contents of the flake availiable to modules.
|
|
|
|
Useful for having the monitoring server scraping the
|
|
|
|
target config from all other servers automatically.
|
|
|
|
*/
|
2023-05-04 14:35:30 +02:00
|
|
|
_module.args = {
|
|
|
|
inputs = inputs;
|
|
|
|
_nixfiles = self;
|
|
|
|
};
|
2024-05-13 17:00:03 +02:00
|
|
|
|
|
|
|
# Expose host group to monitoring
|
2023-04-21 23:03:11 +02:00
|
|
|
clerie.monitoring = nixpkgs.lib.attrsets.optionalAttrs (group != null) { serviceLevel = group; };
|
2024-05-13 17:00:03 +02:00
|
|
|
|
|
|
|
# Automatically load secrets from sops file for host
|
2024-04-20 23:20:14 +02:00
|
|
|
sops.defaultSopsFile = ../hosts + "/${name}/secrets.json";
|
2024-04-21 15:51:25 +02:00
|
|
|
sops.secrets = let
|
|
|
|
secretFile = config.sops.defaultSopsFile;
|
|
|
|
secretNames = builtins.filter (name: name != "sops") (builtins.attrNames (builtins.fromJSON (builtins.readFile secretFile)));
|
|
|
|
secrets = if builtins.pathExists secretFile then
|
|
|
|
lib.listToAttrs (builtins.map (name: lib.nameValuePair name {}) secretNames)
|
|
|
|
else
|
|
|
|
{};
|
|
|
|
in
|
|
|
|
secrets;
|
2024-04-20 23:20:14 +02:00
|
|
|
})
|
2024-05-13 17:00:03 +02:00
|
|
|
|
|
|
|
# Config to be applied to every host
|
|
|
|
../configuration/common
|
|
|
|
../users/clerie
|
|
|
|
|
|
|
|
# Host specific config
|
|
|
|
(../hosts + "/${name}/configuration.nix")
|
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;
|
2024-05-13 17:39:54 +02:00
|
|
|
|
|
|
|
in
|
|
|
|
mapToNixosConfigurations self.clerie.hosts
|