1
0
nixfiles/lib/flake-helper.nix

58 lines
1.9 KiB
Nix
Raw Normal View History

2024-05-13 16:05:48 +02:00
{ self, nixpkgs, fernglas, fieldpoc, nixos-exporter, solid-xmpp-alarm, sops-nix, ... }@inputs:
2023-03-23 16:45:30 +01:00
rec {
generateNixosSystem = {
name,
system ? "x86_64-linux",
2023-04-21 23:03:11 +02:00
group ? null,
modules ? [],
}: let
2023-03-23 17:09:54 +01:00
localNixpkgs = nixpkgs.lib.attrByPath [ "nixpkgs-${name}" ] nixpkgs inputs;
in localNixpkgs.lib.nixosSystem {
system = system;
modules = modules ++ [
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.
*/
_module.args = {
inputs = inputs;
_nixfiles = self;
};
2023-03-23 16:45:30 +01:00
})
../configuration/common
../users/clerie
2023-03-23 16:45:30 +01:00
({ ... }: {
nixpkgs.overlays = [
2024-05-13 16:05:48 +02:00
self.overlays.nixfilesInputs
self.overlays.clerie
2023-03-23 16:45:30 +01:00
];
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
})
fernglas.nixosModules.default
2023-06-20 18:58:55 +02:00
fieldpoc.nixosModules.default
nixos-exporter.nixosModules.default
2023-03-23 16:45:30 +01:00
solid-xmpp-alarm.nixosModules.solid-xmpp-alarm
2024-04-20 23:20:14 +02:00
sops-nix.nixosModules.sops
2023-03-23 16:45:30 +01:00
(../hosts + "/${name}/configuration.nix")
2024-04-20 23:20:14 +02:00
# Automatically load secrets from sops file for host
({ config, lib, ... }: {
2024-04-20 23:20:14 +02:00
sops.defaultSopsFile = ../hosts + "/${name}/secrets.json";
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
})
2023-03-23 16:45:30 +01:00
];
};
mapToNixosConfigurations = hosts: builtins.mapAttrs (name: host: generateNixosSystem host) hosts;
2023-03-23 16:45:30 +01:00
}